Game Development Reference
In-Depth Information
gl.glEnable(GL10. GL_TEXTURE_2D );
batcher.beginBatch(Assets. background );
batcher.drawSprite(240, 160, 480, 320, Assets. backgroundRegion );
batcher.endBatch();
gl.glDisable(GL10. GL_TEXTURE_2D );
renderer.render(world, deltaTime);
switch (state) {
case GAME_RUNNING :
presentRunning();
break ;
case GAME_PAUSED :
presentPaused();
break ;
case GAME_OVER :
presentGameOver();
}
fpsCounter.logFrame();
}
The present() method is actually pretty simple, as well. As always, we start off by clearing
the framebuffer. Also, we clear the z buffer, since we are going to render some 3D objects for
which we need z testing. Next, we set up the projection matrix so that we can render our 2D
background image, just as we did in the MainMenuScreen or SettingsScreen classes. Once
that is done, we tell the WorldRenderer member to render our game world. Finally, we
delegate the rendering of the UI elements depending on the current state. Note that the
WorldRenderer.render() method is responsible for setting up all things needed to render
the 3D world!
private void presentPaused() {
GL10 gl = glGraphics.getGL();
guiCam.setViewportAndMatrices();
gl.glEnable(GL10. GL_BLEND );
gl.glBlendFunc(GL10. GL_SRC_ALPHA , GL10. GL_ONE_MINUS_SRC_ALPHA );
gl.glEnable(GL10. GL_TEXTURE_2D );
batcher.beginBatch(Assets. items );
Assets. font .drawText(batcher, scoreString, 10, 320-20);
batcher.drawSprite(240, 160, 160, 64, Assets. pauseRegion );
batcher.endBatch();
gl.glDisable(GL10. GL_TEXTURE_2D );
gl.glDisable(GL10. GL_BLEND );
}
The presentPaused() method just renders the scoreString via the Font instance we stored in the
Assets class, as well as the Pause menu. Note that, at this point, we have already rendered the
background image, as well as the 3D world. All the UI elements will thus overlay the 3D world.
 
Search WWH ::




Custom Search