-
Notifications
You must be signed in to change notification settings - Fork 0
Animal Selection Display
The AnimalSelectionDisplay
class is responsible for setting up and managing the user interface for the animal selection screen in the game. This class creates the layout for displaying animal images and buttons, and it also provides access to these UI elements for interaction by other components.
The AnimalSelectionDisplay
class is responsible for:
- Creating and organizing the UI elements (images, buttons) used in the animal selection screen.
- Managing the layout and appearance of these elements using a
Stage
andTable
. - Providing access to the UI elements so that actions can be attached to them by other classes.
The constructor initializes the AnimalSelectionDisplay
class by setting up the stage and skin, and then calling the initializeDisplay()
method to create and arrange the UI elements.
public AnimalSelectionDisplay(Stage stage, Skin skin) {
this.stage = stage;
this.skin = skin;
this.animalImages = new Image[3];
this.animalButtons = new TextButton[3];
this.selectButton = new TextButton("Ready?", skin);
this.backButton = new TextButton("Go Back", skin);
initializeDisplay();
}
initializeDisplay(): Sets up the UI layout by creating tables and adding the animal images, buttons, and control buttons (selectButton and backButton) to the stage.
private void initializeDisplay() {
// Used to setup layout and to add UI elements to the stage
}
getAnimalImages(): Returns an array of Image objects representing the animal images displayed on the screen.
public Image[] getAnimalImages() {
return animalImages;
}
getAnimalButtons(): Returns an array of TextButton objects representing the buttons associated with each animal.
public TextButton[] getAnimalButtons() {
return animalButtons;
}
public TextButton getSelectButton() {
return selectButton;
}
public TextButton getBackButton() {
return backButton;
}
public Skin getSkin() {
return skin;
}
public Stage getStage() {
return stage;
}
This class relies on the following components:
- Stage: A 2D scene graph for managing UI elements.
- Skin: Defines the appearance of UI elements.
- Table: A layout widget for organizing UI elements in rows and columns.
- Image: Represents an image displayed in the UI.
- TextButton: A button with text that can be clicked.
To use AnimalSelectionDisplay, instantiate it by passing a Stage and Skin, and then use its methods to access and interact with the UI elements:
Stage stage = new Stage();
Skin skin = new Skin(Gdx.files.internal("flat-earth/skin/flat-earth-ui.json"));
AnimalSelectionDisplay display = new AnimalSelectionDisplay(stage, skin);
Image[] animalImages = display.getAnimalImages();
TextButton selectButton = display.getSelectButton();
The layout of the UI elements is managed using a Table, which provides flexibility in arranging components on the screen. The initializeDisplay() method sets up the UI, so any changes to the layout should be made there. Ensure that the textures for the animal images are correctly loaded to avoid runtime errors.
For Sprint 2, new additions Animal Screen Kingdom have been made corresponding to the specific Land and Display :