Skip to content

MiniScreenDisplay

24msingh24 edited this page Sep 14, 2023 · 3 revisions

Description

The MiniScreenDisplay class is a user interface component used in the initial sequence of a game. It displays a background image and a button to launch the game mission. This WikiDoc provides detailed information about the class's constructor and methods.iniScreenDisplay(GdxGame game): Constructs a MiniScreenDisplay instance, taking a GdxGame instance as a parameter.

Constructors

public MiniScreenDisplay(GdxGame game) {
    this.game = game;

Methods

addUIElements()

  • Description: This method is responsible for adding UI elements, including a background image and a "Launch Mission" button, to the screen. It also sets up the layout of these elements.

  • Parameters:

  • delta: The time elapsed since the last render frame.

Usage: Call this method to render the content of the mini-screen.

public void addUIElements() {
       background =
                new Image(
                        ServiceLocator.getResourceService()
                                .getAsset("images/RELAUNCH MISSION-2.png", Texture.class));
        background.setPosition(0, 0);

        // Scale the height of the background to maintain the original aspect ratio of the image
        float scaledHeight = Gdx.graphics.getWidth() * (background.getHeight() / background.getWidth());
        background.setHeight(scaledHeight);

        // Create a button to launch the game mission
        TextButton LaunchMissionButton = new TextButton("Launch Mission", skin);

        LaunchMissionButton.addListener(new ChangeListener() {

            public void changed(ChangeEvent changeEvent, Actor actor) {
                logger.debug("LaunchMission button clicked");
                startGame();
}

startGame()

  • Description: Method signature: public void startGame() This method is called when the "Launch Mission" button is clicked. It initiates the start of the game mission, transitioning the game to the ScreenType.SPACE_MAP.
 public void startGame() {
        game.setScreen(ScreenType.SPACE_MAP);
    }

draw(SpriteBatch batch)

  • Description: Method signature: protected void draw(SpriteBatch batch) This method handles the drawing of UI components. However, in this implementation, drawing is delegated to the stage and is not handled directly in this method. .
 @Override
  protected void draw(SpriteBatch batch) {
        // Drawing is handled by the stage
    }

update()

  • Description: Method signature: public void update() This method is responsible for updating UI components, particularly the stage. It ensures that UI elements respond to changes and user interactions.
public void update() {

        stage.act(ServiceLocator.getTimeSource().getDeltaTime());
    }
}

}

dispose()

  • Description: UMethod signature: public void dispose() This method disposes of resources and cleans up when the MiniScreenDisplay is no longer needed. It clears the root table and background, and it also calls the super.dispose() method to handle additional disposal.
 @Override
    public void dispose() {
        rootTable.clear();
        background.clear();
        super.dispose();
    }


Clone this wiki locally