Using the HUD and Renderer classes
Declare an instance of the HUD and Renderer classes as members of the GameEngine class 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 as highlighted next:
@Override
public void run() {
while (mGameState.getThreadRunning()) {
long frameStartTime = System.currentTimeMillis();
...