-
Notifications
You must be signed in to change notification settings - Fork 1
MiniGame Menu Screen
rp3002 edited this page Oct 1, 2024
·
4 revisions
The MiniGameMenuScreen
class provides players with a menu to select among various mini-games, including Snake, BirdieDash and Under-water maze mini games. Players can choose to play any mini-games or navigate back to the main menu for the main game. This screen utilises LibGDX's Scene2D module for managing UI elements and handling user input.
public class MiniGameMenuScreen implements Screen {
private Stage stage;
private BitmapFont font;
private final GdxGame game;
private Skin skin;
private SpriteBatch batch;
private Texture snakeTexture;
private Texture skyTexture;
private Texture waterTexture;
private Texture backgroundTexture;
}
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.csse3200.game.GdxGame;
-
Called when the screen is shown for the first time
-
Setup:
- Initialises
Stage
,SpriteBatch
,BitmapFont
, andSkin
. - Loads textures for the background and mini-game icons.
- Initialises
-
UI Elements:
- Creates
TextButton
for exiting the menu and selecting mini-games. - Creates
Image
for mini-game icons (Snake, Flappy Bird, Underwater Maze).
- Creates
-
Layout:
- Arranges UI elements using
Table
. - Adds images and buttons to the table and positions it on the screen.
- Arranges UI elements using
-
Listeners:
- Adds click listeners to buttons and images to handle user input, such as changing the screen or updating UI colors.
-
Background Rendering:
- Clears the screen with a specified colour.
- Draws the background texture using
SpriteBatch
.
-
UI Updates:
- Updates and renders the stage to reflect any changes.
-
Input Handling:
- Checks for the Escape key to return to the main menu.
- parameters: width and height of the new screen
- Called when the screen is resized
- Called when the game is paused
Called when the game is resumed after a pause
- Called when the screen is hidden
- Called to dispose of resources to prevent memory leaks