Drawing at 60 + FPS
In three simple steps, we will be able to glimpse our spaceship:
Add a
SpaceShip
object to theGameManager
member variables:private boolean playing = false; // Our first game object SpaceShip ship; int screenWidth;
Add a call to the new
SpaceShip()
to thecreateObjects
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 ofAsteroidsRenderer
:// 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...