Game Development Reference
In-Depth Information
TouchEvent event = touchEvents.get(i);
if (event.type != TouchEvent. TOUCH _ UP )
continue ;
world = new World(worldListener);
renderer = new WorldRenderer(glGraphics, batcher, world);
world.score = lastScore;
state = GAME _ READY ;
}
}
In the updateLevelEnd() method, we check for a touch event; if there has been one, we create a
new World and WorldRenderer instance. We also tell the World to use the score achieved so far
and set the game screen to the GAME_READY state, which will again wait for a touch event.
private void updateGameOver() {
List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
int len = touchEvents.size();
for ( int i = 0; i < len; i++) {
TouchEvent event = touchEvents.get(i);
if (event.type != TouchEvent. TOUCH _ UP )
continue ;
game.setScreen( new MainMenuScreen(game));
}
}
In the updateGameOver() method, we again just check for a touch event, in which case we simply
transition back to the main menu, as indicated in Figure 9-2 .
Rendering the GameScreen
After all those updates, the game screen will be asked to render itself via a call to GameScreen.
present() . Let's have a look at that method in Listing 9-22.
Listing 9-22. Excerpt from GameScreen.java; the Rendering Methods
@Override
public void present( float deltaTime) {
GL10 gl = glGraphics.getGL();
gl.glClear(GL10. GL _ COLOR _ BUFFER _ BIT );
gl.glEnable(GL10. GL _ TEXTURE _ 2D );
renderer.render();
guiCam.setViewportAndMatrices();
gl.glEnable(GL10. GL _ BLEND );
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
batcher.beginBatch(Assets. items );
switch (state) {
case GAME _ READY :
presentReady();
break ;
 
Search WWH ::




Custom Search