O'Reilly logo

Beginning Android Tablet Games Programming by Jeremy Kerfs

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

Preparing the Game Environment

Before you can work on the game loop for, you must initiate all of these new sprites—paddle, ball, and blocks—each of which has different attributes and properties. You also have to prepare the environment—the game surface—in which the sprites are used. Let’s start by changing the source files you opened in the previous section to prepare the way for your new game.

Modifying SpriteObject.java

SpriteObject.java needs an extra function to return the MoveX and MoveY values, which are the variables that store the horizontal and vertical velocity of the sprites. In this way, you can easily reverse them to cause the ball to switch directions. In other game types, you may want to check the speed of a sprite to make sure ...

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