Coding the GameState
The GameState
class has exactly the same role as in the previous project. Obviously, however, the details of the state in this project is different. In the previous project we had score, high score lasers and aliens; in this one we have time, multiple fastest times and which level is being played. The GameState
class also takes care of knowing (and sharing) the current state of paused, playing, drawing, thread running, etc.
Create a new class called GameState
and add the member variables and constructor as shown next.
import android.content.Context; import android.content.SharedPreferences; final class GameState { private static volatile boolean mThreadRunning = false; private static volatile boolean mPaused = true; private ...
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.