Game Development Reference
In-Depth Information
The three bunny head images that will represent the extra lives of the player are drawn
in the top-right corner of the screen. The method starts to draw from left to right.
Before a new bunny head is drawn, there is an additional check to find out whether
this extra life is used up already. If this is the case, the bunny head is darkened and
gets a slightly transparent look by setting the tint color of the sprite batch.
The GUI FPS counter
The following is a screenshot of the GUI element that shows the actual frames
per second:
Add the following code in WorldRenderer :
private void renderGuiFpsCounter (SpriteBatch batch) {
float x = cameraGUI.viewportWidth - 55;
float y = cameraGUI.viewportHeight - 15;
int fps = Gdx.graphics.getFramesPerSecond();
BitmapFont fpsFont = Assets.instance.fonts.defaultNormal;
if (fps >= 45) {
// 45 or more FPS show up in green
fpsFont.setColor(0, 1, 0, 1);
} else if (fps >= 30) {
// 30 or more FPS show up in yellow
fpsFont.setColor(1, 1, 0, 1);
} else {
// less than 30 FPS show up in red
fpsFont.setColor(1, 0, 0, 1);
}
fpsFont.draw(batch, "FPS: " + fps, x, y);
fpsFont.setColor(1, 1, 1, 1); // white
}
 
Search WWH ::




Custom Search