Skip to content

Animal Selection Screen

Shaivika Anand edited this page Sep 11, 2024 · 6 revisions

AnimalSelectionScreen

Overview

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.

Purpose

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 and AnimalSelectionActions components to separate UI logic from game logic.

Structure

Constructor

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
}

Methods

render(float delta): Clears the screen and renders the stage with the current delta time.

public void render(float delta) {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    stage.act(Gdx.graphics.getDeltaTime());
    stage.draw();
}

resize(int width, int height): Updates the stage's viewport size when the screen is resized.

@Override
public void resize(int width, int height) {
    stage.getViewport().update(width, height, true);
}

dispose(): Disposes of the stage to free up resources.

@Override
public void dispose() {
    stage.dispose();
}

Dependencies

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.

Usage

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);

Animal Selection Screen

Additions

For Sprint 2, new additions Animal Screen Kingdom have been made corresponding to the specific Land and Display :

AnimalSelectionDisplay-for-Land,-Water,-and-Air

Clone this wiki locally