Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
As usual we have a main activity that derives from the GLGame class. It is responsible for loading the assets through a call to Assets.load() on startup as well as pausing and resuming the music when the activity is paused or resumed. As the start screen we just return the MainMenuScreen, which we will implement shortly. One thing to remember is the definition of the activity in the manifest file. Make sure you have the orientation set to landscape! Listing 12-3 shows you the code.
package com.badlogic.androidgames.droidinvaders; import javax.microedition.khronos.egl.EGLConfig;
Code View:
Scroll
/
Show All import javax.microedition.khronos.opengles.GL10;
import com.badlogic.androidgames.framework.Screen;
import com.badlogic.androidgames.framework.impl.GLGame;
public class DroidInvaders extends GLGame {
boolean firstTimeCreate = true ;
@Override
public Screen getStartScreen() {
return new MainMenuScreen(this );
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
super .onSurfaceCreated(gl, config);
if (firstTimeCreate) {
Settings.load (getFileIO());
Assets.load (this );
firstTimeCreate = false ;
} else {
Assets.reload ();
}
}
@Override
public void onPause() {
super .onPause();
if (Settings.soundEnabled )
Assets.music .pause();
}
}
|