Game Development Reference
In-Depth Information
int startFrame
// The total number of frames for said anima-
tion
int numFrames
end
We would then have an AnimData struct that stores both the array of all the pos-
sible images, as well as the FrameData corresponding to each particular anima-
tion:
Click here to view code image
struct AnimData
// Array of images for all the animations
ImageFile images []
// The frame data for all the different anima-
tions
AnimFrameData frameInfo []
end
Wethenneedan AnimatedSprite classthatinheritsfrom Sprite .Because it
inherits from Sprite , it will already have position and draw order functionality,
as well as the ability to draw a single ImageFile . However, because an Anim-
atedSprite is much more complicated than a single-image Sprite , several
additional member variables are required.
AnimatedSprite must track the current animation number, the current frame
in that animation, and the amount of game time the current frame has been dis-
played. You may notice that the animation FPS is also stored as a separate member
variable. This allows the animation to dynamically speed up or slow down. For in-
stance, as a character gains speed, it would be possible to have the run animation
play more rapidly.
Click here to view code image
class AnimatedSprite inherits Sprite
// All of the animation data (includes
ImageFiles and FrameData)
AnimData animData
// The particular animation that is active
int animNum
Search WWH ::




Custom Search