Frame Animation Revisited


Back in Hour 9, "A Crash Course in Game Animation," you learned all about animation, including the two fundamental types of animation: frame-based animation and cast-based (sprite) animation. Although you learned that both types of animation are equally useful, you've focused solely on sprite animation since Hour 9 because it is more immediately useful in terms of allowing you to move objects around on the game screen. However, frame-based animation, or frame animation for short, is still very important to games. In fact, you'll find that the ideal usage of frame animation in games is when you combine it with sprite animation.

To better understand how frame animation fits in with sprite animation, consider a simple maze game such as Pac-Man. In Pac-Man, the main character moves around the game screen eating dots. To convey the effect of the main character eating , his mouth opens and closes as he moves around. The simple movement of the character is made possible with sprite animation, but the change in his appearance brought on by his mouth moving is made possible by frame animation. In other words, frame animation makes it possible to change the appearance of a sprite, independent of whether the sprite is moving with respect to the game screen.

Okay, so frame animation makes it possible to change the appearance of a sprite, but how does it work? If you recall, a basic sprite without frame animation uses a single bitmap image to reflect its appearance; when you draw the sprite, you are just drawing the bitmap image. A frame-animated sprite relies on a series of bitmap images to represent more than one appearance for the sprite. You can think of this series of images as a roll of film on a traditional film projector. The illusion of frame animation is made possible by cycling through the images on the roll of film. Figure 17.1 shows how this concept applies to adding animation to the Pac-Man character.

Figure 17.1. A series of images shows how frame animation can make Pac-Man appear to be eating something.

graphics/17fig01.gif

In the figure, the Pac-Man character consists of a series of four images. When this image series is incorporated into a game and played in sequence, the effect will be that Pac-Man is moving his mouth and eating something. If you look carefully , you'll notice that frame 4 is the same as frame 2. This is necessary because the animation sequence cycles back to frame 1 when it finishes, so duplicating frame 2 provides a smooth transition back to the first frame. Just visualize the frames being displayed in succession to see what I'm talking about.

One problem associated with frame animation is that of controlling how fast the frame images are cycled through. For example, a frame-animated Pac-Man sprite might need to change its appearance slower than an animated sprite of an explosion, for example. For this reason, there needs to be a way to establish a timing delay that controls how fast the frames change. Increasing the delay would slow down the frame animation, which in some cases would be a desirable effect. You will definitely take a frame delay into consideration as you design and develop frame animation support for the game engine throughout the remainder of this hour.



Sams Teach Yourself Game Programming in 24 Hours
Sams Teach Yourself Game Programming in 24 Hours
ISBN: 067232461X
EAN: 2147483647
Year: 2002
Pages: 271

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net