Home Contents Forum Links Tip Jar
Animation Math in Lingo       

The Standard Behavior Script

This is the standard form of the behavior scripts in this tutorial:

property sp
-- and other variables declared as properties

on beginsprite me
  sp = sprite(me.spritenum)
  -- variables initialized
end

on exitframe me
  -- animation algorithm performed
  -- sprite properties updated

end

Any variables that need to retain their values between the execution of handlers must be declared as properties. A property called sp will usually be declared in the scripts of the tutorial.

The beginsprite handler executes once when the playback head first encounters the sprite in the score. This makes it a good place to set the initial values of variables.

Throughout the tutorial, the statement "sp = sprite(me.spritenum)" will be found in the beginsprite handler so it's good to understand it. The expression me.spritenum evaluates to the sprite number of whatever sprite the script is attached to. So the expression sprite(me.spritenum) evaluates to a pointer to that sprite. After setting sp equal to the pointer, it can be used instead of the expression sprite(me.spritenum). This is done to simplify the code.

The stage is redrawn by Director every frame, which makes the frame the unit of animation time in Director. Updating the properties of an animated object once each frame is the standard practice. This is conveniently done in an exitframe handler, which gets executed by Director once every frame.

 
 


Copyright © 2003 JM Harward 
 jmckell~at~jmckell~dot~com
All lingo provided on this site may be used freely for educational purposes. Not for redistribution as uncompiled code. Instructional materials may not be reproduced without permission.