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 ...
Get Android Game Programming: A Developer’s Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.