Game Development Reference
In-Depth Information
case GAME_RUNNING:
presentRunning();
break ;
case GAME_PAUSED:
presentPaused();
break ;
case GAME_LEVEL_END:
presentLevelEnd();
break ;
case GAME _ OVER :
presentGameOver();
break ;
}
batcher.endBatch();
gl.glDisable(GL10. GL _ BLEND );
}
Rendering of the game screen is done in two steps. We first render the actual game world via the
WorldRenderer class, and then render all the UI elements on top of the game world depending
on the current state of the game screen. The render() method does just that. As with our update
methods, we again have a separate rendering method for all the subscreens.
private void presentReady() {
batcher.drawSprite(160, 240, 192, 32, Assets. ready );
}
The presentRunning() method just displays the pause button in the top-right corner and the
score string in the top-left corner.
private void presentRunning() {
batcher.drawSprite(320 - 32, 480 - 32, 64, 64, Assets. pause );
Assets. font .drawText(batcher, scoreString, 16, 480-20);
}
In the presentRunning() method, we simply render the pause button and the current score
string.
private void presentPaused() {
batcher.drawSprite(160, 240, 192, 96, Assets. pauseMenu );
Assets. font .drawText(batcher, scoreString, 16, 480-20);
}
The presentPaused() method displays the pause menu UI elements and the score again.
private void presentLevelEnd() {
String topText = "the princess is ...";
String bottomText = "in another castle!";
float topWidth = Assets. font .glyphWidth * topText.length();
float bottomWidth = Assets. font .glyphWidth * bottomText.length();
Assets. font .drawText(batcher, topText, 160 - topWidth / 2, 480 - 40);
Assets. font .drawText(batcher, bottomText, 160 - bottomWidth / 2, 40);
}
Search WWH ::




Custom Search