O'Reilly logo

LibGDX Cross-Platform Development Blueprints by Indraneel Potnis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Keeping the score and maintaining the high score

In this topic, we will learn how to display the game score and save the high score. We will also see how to use custom fonts to display text on the screen.

Keeping the score

We want to keep track of how many times the user has collected the ball and show it to him. So, we add a new variable to the GameManager class called score:

public static int score;

Let's initialize it to 0 in the initialize() method:

score=0;

To display the score, we are going to add a new class called TextManager to the com.packtpub.catchtheball.managers package, similar to what we did previously:

package com.packtpub.catchtheball.managers; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.BitmapFont; import ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required