Game Development Reference
In-Depth Information
import com.badlogic.androidgames.framework.Screen;
import com.badlogic.androidgames.framework.impl.GLGame;
public class AndroidInvaders 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 (firstTimeCreate) {
Settings. load (getFileIO());
Assets. load ( this );
firstTimeCreate = false ;
} else {
Assets. reload ();
}
}
@Override
public void onPause() {
super .onPause();
if (Settings. soundEnabled )
Assets. music .pause();
}
}
This is exactly the same as in Super Jumper. On a call to getStartScreen() , we return a new
instance of the MainMenuScreen that we'll write next. In onSurfaceCreated() , we make sure our
assets are reloaded, and in onPause() , we pause the music if it is playing.
As you can see, there are a lot of things that can be repeated once you have a good idea of
how to approach the implementation of a simple game. Think about how you could reduce the
boilerplate code even more by moving things to the framework!
The Main Menu Screen
We've already written many trivial screens for the previous games. Android Invaders also has
some of these. The principle is always the same: offer some UI elements to click and trigger
transitions or configuration changes, and display some information. The main menu screen
presents only the logo and the PLAY and SETTINGS options, as shown earlier in Figure 12-4 .
Touching one of these buttons triggers a transition to the GameScreen or the SettingsScreen .
Listing 12-4 shows the code.
 
Search WWH ::




Custom Search