Textbox Display - UQcsse3200/2024-studio-3 GitHub Wiki
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.
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.
Takes a String input and splits it into chunks based on a defined character limit.
Returns the list of the split text which will be displayed
Sets the visibility of the text display. If true, the text box and label will be shown; otherwise, they will be hidden.
Returns the current visibility state of the text display.
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.
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.
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);
}
}