Textbox Display - UQcsse3200/2024-studio-3 GitHub Wiki

Overview

The TextDisplay class is a UI component created for the purpose of rendering and managing text display in the game. It allows for the slow, typewriter-like reveal of text, which can be broken into parts for multi-step displays. This class is particularly useful for displaying narrative text, dialogues, or other forms of sequential information to the player.

Methods in TextDisplay.java

void create()

Initializes the UI elements and sets up the layout, including a stack that contains the text box image and label for text display. It also sets up input listeners and event listeners.

void setText(String text)

Takes a String input and splits it into chunks based on a defined character limit.

List getText()

Returns the list of the split text which will be displayed

void setVisible(Boolean value)

Sets the visibility of the text display. If true, the text box and label will be shown; otherwise, they will be hidden.

boolean getVisible()

Returns the current visibility state of the text display.

void update()

Handles the logic for updating the text display, revealing one character at a time based on the delay. This method is called continuously to drive the typewriter effect.

void setupInputListener()

Sets up an input listener for the stage that listens for the ENTER key. When pressed, it moves to the next part of the text. If all parts have been displayed, it hides the text display.

How to use

To create your own text display, you can simply use the setText function which will automatically make the textbox visible. A example of creating a textbox is shown in ForestGameArea.java. The code below shows the functions which creates the textbox for this area

private void createTextBox(String text) {
    for (Entity entity: ServiceLocator.getEntityService().getEntities()) {
      entity.getEvents().trigger("SetText", text);
    }
}
⚠️ **GitHub.com Fallback** ⚠️