Game Development Reference
In-Depth Information
batcher.endBatch();
}
@Override
public void pause() {
}
@Override
public void dispose() {
}
}
Finally, we have the present() method. We start off by clearing the screen and setting the
viewport and projection matrix via our camera. Next, we enable blending and texture mapping,
and set the blend function. We start rendering by telling the sprite batcher that we want to start
a new batch using the animation texture atlas. Next, we loop through all the cavemen and render
them. For each caveman, we first fetch the correct keyframe from the Animation instance based
on the caveman's walking time. We specify that the animation should be looping. Then we draw
the caveman with the correct texture region at his position.
But what do we do with the width parameter here? Remember that our animation texture only
contains keyframes for the “walk left� animation. We want to flip the texture horizontally in case
the caveman is walking to the right, which we can do by specifying a negative width. If you don't
trust us, go back to the SpriteBatcher code and check whether this works. We essentially flip
the rectangle of the sprite by specifying a negative width. We could do the same vertically, as
well, by specifying a negative height.
Figure 8-26 shows our walking cavemen.
Figure 8-26. Cavemen walking
 
Search WWH ::




Custom Search