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

Reusing existing classes

Let's quickly add our SoundManager and InputController classes to this project because they only need a little tweak to accommodate our needs here too.

Add a member for a SoundManager and an InputController object in both the AsteroidsView and AsteroidsRenderer classes.

private InputController ic;
private SoundManager sm;

Initialize the new objects in the onCreate method of the AsteroidsView class and call the loadSound method like this:

public AsteroidsView(Context context, int screenX, int screenY) {
  super(context);

     sm = new SoundManager();
     sm.loadSound(context);
     ic = new InputController(screenX, screenY);
     gm = new GameManager(screenX, screenY);

Also in AsteroidsView, add an extra two arguments to the call to the AsteroidsRenderer ...

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