Pausing a simple animation

Dave Cragg dcragg at lacscentre.co.uk
Fri May 16 02:32:01 EDT 2003


At 4:27 pm -0400 15/5/03, Jim Biancolo wrote:
>Hi again folks,
>
>I thought I had this, but I'm still stumped.  I thought if I had my
>"play" button invoke a different handler using "send in 10
>milliseconds" then the "on mouseUp" event of the play button would
>end instantly (in effect) and other buttons would be clickable while
>the animation was running (including my "pause" button).  This does
>not seem to be the case.  When I hit "play" this code runs:


>on mouseUp
>    send animateTokens to card "myCanvas" in 10 milliseconds
>end mouseUp
>
>This invokes the handler:
>
>on animateTokens
>   global b_play
>   put TRUE into b_play
>   repeat for each line L in field "frames"
>     set the lockMoves to true
>     repeat with i = 1 to the number of images in group "tokens_group"
>       move image i of group "tokens_group" to coords without waiting
>     end repeat
>     set the lockMoves to false
>     if not b_play then break
>   end repeat
>end animateTokens
>
>Unfortunately "pause" remains unclickable for the duration of
>"animateTokens" so there's no chance for it to set the global
>"b_play" to FALSE until after the animation is already done.
>
>On the bright side, I no longer feel like I'm missing something
>obvious.  :-)  Can anybody help?
>
>Thanks!

Your first thought was partly right -- the mouseUp handler will end 
instantly. The problem is that the animateTokens handler will run 10 
milliseconds later, and while it is running, nothing else will.

I think what you need to do is remove the outer repeat loop from your 
handler, and complete each stage of the animation with another "send 
.... in x milliseconds". Then your other buttons will respond.

I take it the pause button sets the b_play global to false. It might 
be a good if the "play" button sets it to true and not the animation 
handler. Then you could do something like this:

local lvStage
local b_play ### or global if needed

on mouseUp
    put true into b_play
    put 1 into lvStage
   send animateTokens to card "myCanvas" in 10 milliseconds
end mouseUp

on animateTokens
   if b_play then
     get line lvStage of field "frames"
     ## not sure what you do with this

     set the lockMoves to true
     repeat with i = 1 to the number of images in group "tokens_group"
       move image i of group "tokens_group" to coords without waiting
     end repeat
     set the lockMoves to false
     add 1 to lvStage
     if lvStage > the number of lines of field "frames" then
       put false into b_play
     end if
     send "animateTokens" to me in 50 milliseconds ##adjust timing here
   end if
end animateTokens

Cheers
Dave



More information about the use-livecode mailing list