Using the HUD and Renderer classes

Declare an instance of the HUD and Renderer classes as members of GameEngine as highlighted in this next code.

class GameEngine extends SurfaceView implements Runnable,
GameStarter {
    private Thread mThread = null;
    private long mFPS;

    private GameState mGameState;
    private SoundEngine mSoundEngine;
    HUD mHUD;
    Renderer mRenderer;

Initialize the instances of the HUD and Renderer classes in the GameEngine constructor as highlighted next.

public GameEngine(Context context, Point size) {
   super(context);

   mGameState = new GameState(this, context);
   mSoundEngine = new SoundEngine(context);
   mHUD = new HUD(size);
   mRenderer = new Renderer(this);
}

Now we can add a call to the draw method of the Renderer class in the run method ...

Get Learning Java by Building Android Games - Second Edition 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.