MiniScreen Class - UQcsse3200/2023-studio-2 GitHub Wiki

Description

The MiniScreen class is a fundamental component of the game's user interface, responsible for displaying an initial mini-screen. It initializes various game services, loads essential game assets, and creates the user interface elements for the mini-screen. This class is vital for the introductory sequence of your game.

Constructors

 * Constructs a MiniScreen instance.
 *
 * @param game The GdxGame instance that manages the game.
 */
public MiniScreen(GdxGame game) {
    this.game = game;

Methods

render(float delta)

  • Description: Renders the mini-screen.
  • Parameters:
  • delta: The time elapsed since the last render frame.

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

public void render(float delta) {
    ServiceLocator.getEntityService().update();
        renderer.render();
}

resize(int width, int height)

  • Description: Resizes the mini-screen when the game window size changes.
  • Parameters: width: The new width of the game window. height: The new height of the game window.
  • Usage: Call this method to adjust the mini-screen's size when the game window is resized.
@Override
public void resize(int width, int height) {
    renderer.resize(width, height);
}

dispose()

  • Description: Disposes of resources and clears services when the mini-screen is no longer needed.
  • Usage: Call this method when the mini-screen is no longer in use to release resources and services.
@Override
public void dispose() {
     renderer.dispose();
        ServiceLocator.getRenderService().dispose();
        ServiceLocator.getEntityService().dispose();

        unloadAssets();
        ServiceLocator.clear();
}

Private Methods

loadAssets()

  • Description: Loads required game assets, such as image textures.
  • Usage: Called during initialization to load necessary assets.
private void loadAssets() {
   logger.debug("Loading assets");
        ResourceService resourceService = ServiceLocator.getResourceService();
        resourceService.loadTextures(introScreenAssets);
        ServiceLocator.getResourceService().loadAll();
}

}

unloadAssets()

  • Description: Unloads game assets that are no longer needed.
  • Usage: Called when the mini-screen is disposed to free up memory.
     logger.debug("Unloading assets");
        ResourceService resourceService = ServiceLocator.getResourceService();
        resourceService.unloadAssets(introScreenAssets);
}

createUI()

  • Description: Creates the user interface elements for the mini-screen, including a background image and a button to launch the game mission.
  • Usage: Called during initialization to set up the mini-screen's UI.
private void createUI() {
    logger.debug("Creating UI");
        Stage stage = ServiceLocator.getRenderService().getStage();
        Entity ui = new Entity();
        ui.addComponent(new MiniScreenDisplay(game))
                .addComponent(new InputDecorator(stage, 12));
        ServiceLocator.getEntityService().register(ui);
}

Flow

![](uml.jpg)