|
The Standard Behavior Script
This is the standard form of the behavior scripts in this
tutorial:
property
sp
on beginsprite
me
sp = sprite(me.spritenum)
end
on exitframe
me
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.
|