Game Development Reference
In-Depth Information
Listing 9-3. SuperJumper.java, the Main Entry Point Class
package
com.badlogic.androidgames.jumper;
import
javax.microedition.khronos.egl.EGLConfig;
import
javax.microedition.khronos.opengles.GL10;
import
com.badlogic.androidgames.framework.Screen;
import
com.badlogic.androidgames.framework.impl.GLGame;
public class
SuperJumper
extends
GLGame {
boolean
firstTimeCreate =
true
;
public
Screen getStartScreen() {
return new
MainMenuScreen(
this
);
}
@Override
public void
onSurfaceCreated(GL10 gl, EGLConfig config) {
super.onSurfaceCreated(gl, config);
if
if(firstTimeCreate) {
Settings.load(getFileIO());
Assets.load(
this
);
firstTimeCreate =
false
;
}
else
{
Assets.reload();
}
}
@Override
public void
onPause() {
super.onPause();
if
if(Settings.soundEnabled)
Assets.music.pause();
}
}
We derive from
GLGame
and implement the
getStartScreen()
method, which returns a
MainMenuScreen
instance. The other two methods are a little less obvious.
We override
onSurfaceCreate()
, which is called each time the OpenGL ES context is re-created
(compare with the code of
GLGame
in Chapter 7. If the method is called for the first time, we use
the
Assets.load()
method to load all assets and also load the settings from the settings file on
the SD card, if available. Otherwise, all we need to do is reload the textures and start playback
of the music via the
Assets.reload()
method. We also override the
onPause()
method to pause
the music if it is playing. We do both of these things so that we don't have to repeat them in the
resume()
and
pause()
methods of our screens.
Before we dive into the screen implementations, let's have a look at our new
Font
class.