O'Reilly logo

Android Game Programming by Example by 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

The thrill of flight – scrolling the background

Implementing our space dust is going to be really quick and easy. All we will do is create a SpaceDust class with very similar properties to our other game objects. Spawn them into the game at a random location, move them toward the player at a random speed, and respawn them on the far right of the screen, again with a random speed and y coordinate.

Then in our TDView class, we can declare a whole array of these objects, update, and draw them each frame.

Create a new class and call it SpaceDust. Now enter this code:

public class SpaceDust { private int x, y; private int speed; // Detect dust leaving the screen private int maxX; private int maxY; private int minX; private int minY; // Constructor public ...

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