Sprite Animation

If you've ever played a 2D video game, you know that you are still missing a vital component: sprite animation. The animation consists of so-called keyframes, which produce the illusion of movement. Figure 8–25 shows a nice animated sprite by Ari Feldmann (part of his royalty-free SpriteLib).


Figure 8–25. A walking caveman, by Ari Feldmann (grid not in original)

The image is 256×64 pixels in size, and each keyframe is 64×64 pixels. To produce animation, you just draw a sprite using the first keyframe for an amount of time—say, 0.25 s—and then you switch to the next keyframe, and so on. When you reach the last frame you have ...

Get Beginning Android 4 Games Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.