Reader small image

You're reading from  Android Game Programming by Example

Product typeBook
Published inJun 2015
Reading LevelIntermediate
Publisher
ISBN-139781785280122
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
John Horton
John Horton
author image
John Horton

John Horton is a programming and gaming enthusiast based in the UK. He has a passion for writing apps, games, books, and blog articles. He is the founder of Game Code School.
Read more about John Horton

Right arrow

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...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Android Game Programming by Example
Published in: Jun 2015Publisher: ISBN-13: 9781785280122

Author (1)

author image
John Horton

John Horton is a programming and gaming enthusiast based in the UK. He has a passion for writing apps, games, books, and blog articles. He is the founder of Game Code School.
Read more about John Horton