Game Development Reference
In-Depth Information
// The frame number of the active animation
that's being displayed
int frameNum
// Amount of time the current frame has been
displayed
float frameTime
// The FPS the animation is running at (24FPS
by default).
float animFPS = 24.0f
function Initialize( AnimData myData , int start-
ingAnimNum )
function UpdateAnim( float deltaTime )
function ChangeAnim( int num )
end
The Initialize function takes in a reference to the corresponding AnimData
for this particular AnimatedSprite . By passing in a reference, an unlimited
number of animated sprites can use the same image data, which will save large
quantities of memory. Furthermore, the function requires passing in the first anim-
ation that will be played so that the remaining member variables can be initialized
by the ChangeAnim function.
Click here to view code image
function AnimatedSprite .Initialize( AnimData myData ,
int startingAnimNum )
animData = myData
ChangeAnim( startingAnimNum )
end
The ChangeAnim function gets called when the AnimatedSprite swaps to a
particular animation. It sets both the frame number and the amount of time in the
frame to zero, and sets the active image to be the first frame in the animation. In
both this function and in UpdateAnim , we use the image variable to represent
the active image. That's because the base class ( Sprite ) uses this variable to de-
termine what it should draw on a particular frame.
Search WWH ::




Custom Search