Book Image

Android Game Programming by Example

By : John Horton
Book Image

Android Game Programming by Example

By: John Horton

Overview of this book

Table of Contents (18 chapters)
Android Game Programming by Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
7
Platformer – Guns, Life, Money, and the Enemy
Index

Animating Bob


Sprite sheet animations work by quickly changing the image drawn to the screen. Exactly like a child may draw the phases of a stick-man moving on the corner of a book, and then quickly flicking through it to make it appear to move.

The frames of Bob's animation are already contained within the player.png file we have been using to represent him.

All we need to do is loop through them one at a time when the player is moving.

This is quite straightforward to implement. We will make a simple animation class that handles the function of keeping time and returning the appropriate part of the sprite sheet when requested. We can then initialize a new animation object for any GameObject that needs to be animated. In addition, when they are being drawn in the draw method of PlatformView, if the object is animated, we will handle it slightly differently.

In this section, we will also see how to use the facing variable that tracks which way the player is facing. It will enable us to reverse...