Every game has information that the player needs to know, and LibGDX tackles this with an API called Scene2D to help us develop and manage the UI with easy, clean, and powerful implementations.
The preceding image is an example of the UI for our game. It's displaying the Score (top left), a Health bar, an Oxigen bar, and an Energy bar (bottom middle), and a pause button (top right).
Scene2D is LibGDX's scene graph; its basically, a scene where actors play. It consists of scenes that contain nods and can contain them on various layers. The benefit of using this approach is based on performance, productivity, portability, and scalability.
Using Scene2D is as simple as instantiating a Stage
class and adding actors to it.
We'll start with creating a class that will handle all UI draws and changes; we'll add what we need on GameScreen.java
first:
public class GameScreen implements Screen { ... GameUI gameUI; public GameScreen(Core game) { ... ...