-
Notifications
You must be signed in to change notification settings - Fork 0
Animal Selection Screen
The AnimalSelectionScreen
class is a custom screen in the game that handles the display and actions related to selecting animals. It is built using LibGDX and extends ScreenAdapter
, providing methods to manage the screen's lifecycle, including rendering, resizing, and disposing of resources.
The AnimalSelectionScreen
is responsible for:
- Displaying a selection of animals for the player to choose from.
- Handling user input for selecting an animal.
- Managing transitions between the selection screen and other game screens.
- Utilizing the
AnimalSelectionDisplay
andAnimalSelectionActions
components to separate UI logic from game logic.
The constructor initializes the screen by setting up the Stage
, loading the UI skin, and creating instances of AnimalSelectionDisplay
and AnimalSelectionActions
.
public AnimalSelectionScreen(GdxGame game) {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
Skin skin = new Skin(Gdx.files.internal("flat-earth/skin/flat-earth-ui.json"));
display = new AnimalSelectionDisplay(stage, skin);
actions = new AnimalSelectionActions(display, dialogHelper, game); // Passed the game instance to actions
}
public void render(float delta) {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
}
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
}
@Override
public void dispose() {
stage.dispose();
}
This screen relies on the following components:
-
AnimalSelectionDisplay
: Handles the UI elements and layout for the animal selection process. -
AnimalSelectionActions
: Manages the interactions and game logic related to the animal selection. -
DialogHelper
: Provides a helper class for managing dialog boxes on the screen.
To use AnimalSelectionScreen
, instantiate it by passing the GdxGame
instance, and set it as the current screen in your game:
GdxGame game = new GdxGame();
AnimalSelectionScreen selectionScreen = new AnimalSelectionScreen(game);
game.setScreen(selectionScreen);
For Sprint 2, new additions Animal Screen Kingdom have been made corresponding to the specific Land and Display :