Chapter 17
Keeping Time
Some games, perhaps the one you are developing, are time based. This could mean that a specific challenge in a game has a time limit in which it needs to be completed, or that the entire game itself can only be played for a predetermined amount of time.
The solutions in this chapter will help you create a timer within your game. You will then use that timer to write to the screen, and to exit the game action after expiration. The key component for tracking time within a game is the Android class CountDownTimer(). The CountDownTimer() is a very powerful, yet easy to implement, tool.
17.1 Track Time Within the Game
Problem
The user should only have a set amount of time to complete a task.
Solution
Use a CountDownTimer() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access