Game Development Reference
In-Depth Information
The Game Elements
The actual game objects are dependent on our pixel-to-world unit mappings, as discussed
earlier. To make the creation of the game elements as easy as possible, we used a little trick: we
started each drawing with a grid of 32×32 pixels per cell. All the objects are centered in one or
more such cells, so that they correspond easily with the physical sizes they have in our world.
Let's start with Bob, depicted in Figure 9-9 .
Figure 9-9. Bob and his five animation frames
Figure 9-9 shows two frames for jumping, two frames for falling, and one frame for being dead.
Each image is 160×32 pixels in size, and each animation frame is 32×32 pixels in size. The
background pixels are transparent.
Bob can be in one of three states: jumping, falling, or dead. We have animation frames for each
of these states. Granted, the difference between the two jumping frames and the two falling
frames is minor—only his forelock is wiggling. We'll create an Animation instance for each of
the three animations of Bob, and we'll use them for rendering according to his current state. We
also don't have duplicate frames for Bob heading left. As with the arrow button (shown earlier, in
Figure 9-4 ), we'll just specify a negative width with the SpriteBatcher.drawSprite() call to flip
Bob's image horizontally.
Figure 9-10 depicts the evil flying squirrel. We have two animation frames again, so the squirrel
appears to be flapping its evil wings.
Figure 9-10. An evil flying squirrel and its two animation frames
The image in Figure 9-10 is 64×32 pixels, and each frame is 32×32 pixels.
The coin animation shown in Figure 9-11 is special. Our keyframe sequence will not be 1, 2, 3,
1, but 1, 2, 3, 2, 1. Otherwise, the coin would go from its collapsed state in frame 3 to its fully
extended state in frame 1. We can conserve a little space by reusing the second frame.
 
Search WWH ::




Custom Search