Game Screens - UQcsse3200/2024-studio-2 GitHub Wiki
Introduction
The game contains several screen which which each implement libgdx's ScreenAdapter interface. Screen are responsible for initiating important game services, loading screen resources, drawing the background and UI, rendering the entities, handling input, etc.
Only one screen is shown at a time and GDXGame.java
contains functionality for transitioning between screens. Screen transitions are triggered by the current screen.
Within the base game, there are 3 screens: Main Menu Screen, Main Game Screen, and Loading Screen. The Main Menu Screen is the starting screen. When you click "Start", it will navigate you to the Loading Screen prior to the Main Game Screen. The Setting Screen is now a pop-up window instead of a new screen.
Screens can also be split into different Game Areas which can be used to create different levels and areas. Read more here!
Upon winning or losing the game the user is switched to a game over screen. This is an adaptation of the Main Menu screen which allows the user to exit, giving the game a win condition. The Game Over screen is split into game win or game lose depending on the outcome of combat.
Usage
Add a new screen
Create a new screen class, e.g. NewScreen.
public class NewScreen extends ScreenAdapter {
...
}
Then, register the new screen in GDXGame.java
by adding NEW_SCREEN
to ScreenType
and modifying newScreen
:
private Screen newScreen(ScreenType screenType) {
switch (screenType) {
...
case NEW_SCREEN:
return new NewScreen(this);
...
}
}
public enum ScreenType {
MAIN_MENU, MAIN_GAME, SETTINGS, NEW_SCREEN
}
Switch screen
private void switchScreen(GdxGame game, ScreenType screenType) {
game.setScreen(screenType);
}