MouseMove . . . err?
Scott Rossi
scott at tactilemedia.com
Fri Dec 12 13:21:28 EST 2008
Recently, Richmond Mathewson wrote:
> Just knocked together a silly little stack with 4 buttons called
> "X1", "X2", "X3" and "X4". Now I want them to chase my cursor in
> a quad shape, and to do that I popped this script into my card:
>
> on mouseMove
> set the moveSpeed to 10000
> put item 1 of the mouseLoc into MISHKA1
> put item 2 of the mouseLoc into MISHKA2
> move btn "X1" to (MISHKA1 + 40), (MISHKA2 + 40)
> move btn "X2" to (MISHKA1 - 40), (MISHKA2 + 40)
> move btn "X3" to (MISHKA1 + 40), (MISHKA2 - 40)
> move btn "X4" to (MISHKA1 - 40), (MISHKA2 - 40)
> end mouseMove
>
> [ find "MISHKA.rev" at revOnline, under 'Richmond' ]
>
> but the buttons behave a bit oddly (cannot describe it, has to
> be seen to be understood).
As mentioned by others, it is dangerous to put time-intensive events in the
mouseMove handler because you risk locking up Rev and having to abort. At
the very least, include a trigger that can disable the move events -- make
sure you have some "out" from the script, just in case. And if you want
near-asynchronous movement (not clear if you do), you need to lock/unlock
moves.
I might do something like this:
on mouseMove X,Y
if the hilite of btn "chase" then send "moveThem X,Y" to me
end mouseMove
on moveThem X,Y
set the moveSpeed to 1000
lock moves
move btn "X1" to X+40,Y+40 without waiting
move btn "X2" to X-40,Y+40 without waiting
move btn "X3" to X+40,Y-40 without waiting
move btn "X4" to X-40,Y-40 without waiting
unlock moves
end moveThem
BTW, you don't need to poll the mouseLoc in a mouseMove handler -- mouse
tracking is handled by the engine, with horizontal and vertical coordinates
included in two parameters sent with the mouseMove message.
Regards,
Scott Rossi
Creative Director
Tactile Media, Multimedia & Design
More information about the use-livecode
mailing list