Detect individual Collisions

Geoff Canyon gcanyon at inspiredlogic.com
Wed Mar 3 05:08:22 EST 2004


I'd change the script slightly. First, I'd use the mouseMove handler 
exclusively to avoid the mouseStillDown overhead. Second, I'd store the 
color of the graphic in a script local and only change it if necessary. 
Third (minor) I'd switch the test for the if to test if i is the number 
of the moving graphic first -- Revolution's if tests will fail out at 
the first false statement, so test the easy thing (number vs. number) 
first, and then do the intersection.

local sMoving,sMyColor

on mouseDown
   put true into sMoving
   put the textColor of me into sMyColor
end mouseDown

on mouseUp
   put false into sMoving
end mouseUp

on mouseRelease
   put false into sMoving
end mouseRelease

on mousemove
   if not sMoving then exit mouseMove
   put "red" into tColor
   put the number of me into tMyNumber
   repeat with i = 1 to the number of graphics
     if i is not tMyNumber and intersect (me, graphic (i)) then
       put "green" into tColor
       exit repeat
     end if
   end repeat
   if tColor is not sMyColor then
     set the textcolor of me to tColor
     put tColor into sMyColor
   end if
end mousemove

regards,

Geoff Canyon
gcanyon at inspiredlogic.com

On Mar 2, 2004, at 2:14 AM, Alain Bois wrote:

> on mousemove
>   repeat with i = 1 to the number of graphics
>     if intersect (me, graphic (i)) and i is not the number of me
>     then
>       set the textcolor of me to "green"
>       exit repeat
>     else
>       set the textcolor of me to "red"
>     end if
>   end repeat
> end mousemove



More information about the use-livecode mailing list