Skip to content

Main Menu Display Screen

24msingh24 edited this page Aug 30, 2023 · 3 revisions

This document explains how to use and understand the MainMenuDisplay class, which displays the main menu of the game.

Introduction

The MainMenuDisplay class is a UI component that displays the main menu of the game. It consists of various buttons that trigger different events when clicked.

Getting Started

To integrate the MainMenuDisplay into your game, follow these steps:

1. Add the necessary imports at the beginning of your class:
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.csse3200.game.ui.UIComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// ... other imports ...
2. Create an instance of the MainMenuDisplay class in your game code:
MainMenuDisplay mainMenu = new MainMenuDisplay();
mainMenu.create();

Code Explanation for Space Button

  1. Button Creation: The class creates different buttons, such as "Start," "Load," "Settings," "Exit," "Space," "Space Minigame," and "Extractor Minigame." Each button has a corresponding event that gets triggered when clicked.
  2. Button Listeners: The ChangeListener interface is used to add listeners to the buttons. When a button is clicked, its associated event is triggered, and a log message is generated.
  3. Table Layout: The UI components are added to a Table layout, which is then added to the stage for rendering.

Usage

To use the MainMenuDisplay class, follow these steps:

  1. Create an instance of MainMenuDisplay:
MainMenuDisplay mainMenu = new MainMenuDisplay();
mainMenu.create();
  1. Add the MainMenuDisplay instance to your game's stage:
stage.addActor(mainMenu.getTable());
  1. Make sure to handle the triggered events in your game logic:
mainMenu.getEntity().getEvents().on("space", () -> {
    // Handle space button event
});
// ... other event handlers ...

Conclusion

The MainMenuDisplay class provides an organized way to display the main menu of your game. By following the steps outlined in this document, you can integrate and customize the main menu according to your game's requirements.

Contributor

@24msingh24

Clone this wiki locally