O'Reilly logo

Android: Game Programming by Raul Portales, John Horton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

Drawing at 60 + FPS

Not exactly ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required