-
Notifications
You must be signed in to change notification settings - Fork 9
Modified TitleBox Class
The TitleBox
class is a custom dialog box in a game developed using LibGDX. It is designed to display a title, description, and an "OK" button for providing information to the player in a visually appealing and user-friendly manner.
The TitleBox
class extends the LibGDX Dialog
class and provides the following features:
- Display a title at the top of the dialog.
- Display a description in a scrolling pane.
- Provide an "OK" button for interaction.
- Integration of enhanced visual elements and improved usability within the title box.
- Adding letter-by-letter text animations.
- Installation of TypingLabel library capabilities to TitleBox and DialogueBox classes.
- Asset being used
- Implementation
The TitleBox
class may have dependencies on external libraries or resources. Currently, there are no explicit dependencies mentioned in the provided code snippet.
To use the TitleBox
class in your LibGDX game, follow these steps:
- Create an instance of the
TitleBox
class by providing the necessary parameters, such as the game instance, title, description, skin, and window style name. - Add any event listeners to respond to user interactions with the "OK" button.
- Call the
showDialog(Stage stage)
method to display the dialog on the specified stage.
TitleBox(GdxGame game, String[] title, String[] description, Skin skin, String[] windowStyleName)
- Constructor for creating a
TitleBox
instance.
showDialog(Stage stage)
- Method to display the dialog on the specified stage.
public TitleBox(GdxGame game, String[] title, String[] description, Skin skin, String[] windowStyleName) {
super("", skin, windowStyleName[0]);
this.game = game;
setMovable(false);
setResizable(true);
setSize(Gdx.graphics.getWidth(), 350);
setPosition(0, 0);
Label titleLabel = getTitleLabel();
titleLabel.setText(title[0]);
titleLabel.setAlignment(Align.center);
titleLabel.setFontScale(0.2f);
titleLabel.setColor(Color.BLACK);
descriptionLabel = new TypingLabel("", skin);
// Initialize TypingLabel with your description
descriptionLabel = new TypingLabel(description[0], skin);
descriptionLabel.setAlignment(Align.center);
descriptionLabel.setWrap(true);
descriptionLabel.setColor(Color.BLACK);
TextButton okButton = new TextButton("OK", skin);
button(okButton, true);
Entity entity = new Entity();
okButton.addListener(
new ChangeListener() {
@Override
public void changed(ChangeEvent changeEvent, Actor actor) {
String[] nextMessages = description;
String[] nextTitles = title;
nextIndex++;
if (nextIndex < nextTitles.length) {
getTitleLabel().setText(nextTitles[nextIndex]);
descriptionLabel.setText(nextMessages[nextIndex]);
setStyle(skin.get(windowStyleName[nextIndex], Window.WindowStyle.class));
} else {
remove();
}
entity.getEvents().trigger("ok");
}
}
);
Table buttonTable = new Table();
buttonTable.add(okButton).pad(20f).expandX().center().row();
ScrollPane scrollPane = new ScrollPane(descriptionLabel, skin);
scrollPane.setFadeScrollBars(false);
scrollPane.setScrollingDisabled(true, false);
getContentTable().add(scrollPane).width(Gdx.graphics.getWidth() * 0.8f).height(90f).right().padTop(50f).row();
getContentTable().add(buttonTable).expandX().center();
}
The full code implementation can be found in TitleBox.java
.
- Yash Mittal (@YashMitttal} (s4823869)
- Dev Gupta (@DRG31) (xdrgx)
Escape Earth Game
Interaction Controller and Interactable Components
Game and Entity Configuration Files
Loading Game Configuration Files