Adding game timers
Many games count down time and challenge the player to complete a task within the given amount of time. Such challenges are rewarding for the player, and often add replay value to a game. In the previous recipe, we kept track of the total elapsed time. In this recipe, we will start with a time and subtract from it the elapsed time provided by the update handler.
Getting ready...
Create a new class named GameTimerActivity
that extends BaseGameActivity
. We will use this class to create a game timer from an update handler.
How to do it...
Follow these steps to create a game timer using an update handler:
Place these variable definitions in our new activity class:
public static int cameraWidth = 800; public static int cameraHeight = 480; public Scene mScene; public Font fontDefault32Bold; public Text countingText; public float EndingTimer = 10f;
Next, insert the following standard, overridden methods:
@Override public EngineOptions onCreateEngineOptions() { return new EngineOptions...