Frame-based animation

Ken Corey ken at kencorey.com
Sat Feb 11 07:38:38 EST 2012


On 11/02/2012 12:19, Richard MacLemale wrote:
> I'm creating a variable called frameNumber and each time the loop is triggered I'm adding 1 to it.  Since I've scripted my loop to run 30 times per second, after 1 second the frameNumber would be 30.  OK, so I want certain lines of code to be run at certain frame numbers.  Something like this:
>
> frame 30:
>     set the loc of image "flower" to 400,401
>     set the height of image "flower" to 150
>     set the width of image "flower" to 150
>
> frame 35:
>     hide image "flower"
>
> So imagine I've got a whole big list of commands like that, that I need run at specific frames.  What is the best way to do this?

I'm a LiveCode newbie, but I'd want to minimise the time spent asking 
"is it time for me yet" for each of those commands.

I'd probably try to put the commands into a list ordered on the frame 
number.  Your insert is a little trickier here, because you need to 
preserve the order of the frame number.

Each time through the loop, you look at the first command on the list, 
and if the current frame is less you know no actions are due and ignore 
it, if it matches, remove it from the list and perform the action, and 
then check the next item on the list.

Does that make sense? Is there a better way to handle such things in 
LiveCode?

-Ken




More information about the use-livecode mailing list