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

Drawing at 60 + FPS


In three simple steps, we will be able to glimpse our spaceship:

  • Add a SpaceShip object to the GameManager member variables:

    private boolean playing = false;
    
      // Our first game object
         SpaceShip ship;
    
         int screenWidth;
  • Add a call to the new SpaceShip() to the createObjects method:

    private void createObjects() {
            
      // Create our game objects
      // First the ship in the center of the map
         gm.ship = new SpaceShip(gm.mapWidth / 2, gm.mapHeight / 2);
    }
  • Add the call to draw the spaceship in each frame in the draw method of AsteroidsRenderer:

    // Start drawing!
    // Draw the ship
    gm.ship.draw(viewportMatrix);
    

Run the game and see the output:

Not exactly impressive visuals, but it is running between 67 and 212 frames per second in debug mode while outputting to the console on an ageing Samsung Galaxy S2 phone.

It will be our aim throughout the project to add hundreds of objects and keep the frames per second over 60.

Tip

One of the book's reviewers reported frame rates...