Game Development Reference
In-Depth Information
import com.badlogic.androidgames.framework.Input;
import com.badlogic.androidgames.framework.Screen;
public abstract class GLGame extends Activity implements Game, Renderer {
enum GLGameState {
Initialized ,
Running ,
Paused ,
Finished ,
Idle
}
GLSurfaceView glView;
GLGraphics glGraphics;
Audio audio;
Input input;
FileIO fileIO;
Screen screen;
GLGameState state = GLGameState. Initialized ;
Object stateChanged = new Object();
long startTime = System. nanoTime ();
WakeLock wakeLock;
The class extends the Activity class and implements the Game and GLSurfaceView.Renderer
interface. It has an enum called GLGameState that keeps track of the state that the GLGame
instance is in. You'll see how those are used in a bit.
The members of the class consist of a GLSurfaceView instance and a GLGraphics instance. The
class also has Audio , Input , FileIO , and Screen instances, which we need for writing our game,
just as we did for the AndroidGame class. The state member keeps track of the state via one of
the GLGameState enums. The stateChanged member is an object we'll use to synchronize the UI
and rendering threads. Finally, we have a member to keep track of the delta time and a WakeLock
that we'll use to keep the screen from dimming.
@Override
public void onCreate(Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
requestWindowFeature(Window. FEATURE_NO_TITLE );
getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,
WindowManager.LayoutParams. FLAG_FULLSCREEN );
glView = new GLSurfaceView( this );
glView.setRenderer( this );
setContentView(glView);
glGraphics = new GLGraphics(glView);
fileIO = new AndroidFileIO( this );
audio = new AndroidAudio( this );
input = new AndroidInput( this , glView, 1, 1);
PowerManager powerManager = (PowerManager) getSystemService(Context. POWER_SERVICE );
wakeLock=powerManager.newWakeLock(PowerManager. FULL_WAKE_LOCK , "GLGame");
}
Search WWH ::




Custom Search