Class GameScreenWithHUD

java.lang.Object
nl.saxion.gameapp.screens.GameScreen
nl.saxion.gameapp.screens.GameScreenWithHUD
All Implemented Interfaces:
com.badlogic.gdx.InputProcessor, com.badlogic.gdx.Screen, com.badlogic.gdx.utils.Disposable, HUD, WorldSize
Direct Known Subclasses:
CameraControlledGameScreen, ScalableGameScreen

public abstract class GameScreenWithHUD extends GameScreen implements HUD, WorldSize
A base game screen that provides a fully functional HUD implementation.

Subclasses must implement WorldSize methods to provide world dimensions, world camera, and mouse positions in world space. The HUD is fully managed here.

  • Constructor Details

    • GameScreenWithHUD

      public GameScreenWithHUD()
  • Method Details

    • enableHUD

      public void enableHUD(int width, int height)
      Initializes the HUD with a fixed size.
      Specified by:
      enableHUD in interface HUD
      Parameters:
      width - the HUD width in pixels
      height - the HUD height in pixels
    • getHUDWidth

      public float getHUDWidth()
      Description copied from interface: HUD
      Returns the width of the HUD in world units or pixels, depending on the implementation.
      Specified by:
      getHUDWidth in interface HUD
      Returns:
      the HUD width
    • getHUDHeight

      public float getHUDHeight()
      Description copied from interface: HUD
      Returns the height of the HUD in world units or pixels, depending on the implementation.
      Specified by:
      getHUDHeight in interface HUD
      Returns:
      the HUD height
    • getHUDViewport

      public com.badlogic.gdx.utils.viewport.FitViewport getHUDViewport()
      Description copied from interface: HUD
      Returns the FitViewport used by the HUD.

      The viewport ensures consistent scaling and aspect ratio across different screen resolutions.

      Specified by:
      getHUDViewport in interface HUD
      Returns:
      the HUD's FitViewport
    • getHUDCamera

      public com.badlogic.gdx.graphics.OrthographicCamera getHUDCamera()
      Description copied from interface: HUD
      Returns the OrthographicCamera used for rendering the HUD.

      The camera typically operates in an orthographic projection to simplify 2D rendering of HUD elements.

      Specified by:
      getHUDCamera in interface HUD
      Returns:
      the HUD's OrthographicCamera
    • switchToWorldRendering

      public void switchToWorldRendering()
      Description copied from interface: HUD
      Switches the rendering context from the HUD to the main game world.

      Implementations typically call batch.setProjectionMatrix(worldCamera.combined) or equivalent logic.

      Specified by:
      switchToWorldRendering in interface HUD
    • switchToHudRendering

      public void switchToHudRendering()
      Description copied from interface: HUD
      Switches the rendering context to the HUD.

      Implementations typically call batch.setProjectionMatrix(hudCamera.combined) or equivalent logic before drawing HUD elements.

      Specified by:
      switchToHudRendering in interface HUD
    • getMouseHUDPosition

      public com.badlogic.gdx.math.Vector2 getMouseHUDPosition()
      Description copied from interface: HUD
      Returns the current mouse position in HUD coordinates.

      This can be useful for detecting interactions with UI components or buttons within the HUD.

      Specified by:
      getMouseHUDPosition in interface HUD
      Returns:
      a Vector2 representing the mouse position in HUD space
    • getMouseHUDX

      public float getMouseHUDX()
      Description copied from interface: HUD
      Returns the mouse's X coordinate in HUD space.
      Specified by:
      getMouseHUDX in interface HUD
      Returns:
      the X coordinate of the mouse in HUD coordinates
    • getMouseHUDY

      public float getMouseHUDY()
      Description copied from interface: HUD
      Returns the mouse's Y coordinate in HUD space.
      Specified by:
      getMouseHUDY in interface HUD
      Returns:
      the Y coordinate of the mouse in HUD coordinates
    • worldToHUD

      public com.badlogic.gdx.math.Vector2 worldToHUD(com.badlogic.gdx.math.Vector2 worldPos)
      Description copied from interface: HUD
      Converts a position in world coordinates to HUD coordinates.
      Specified by:
      worldToHUD in interface HUD
      Parameters:
      worldPos - the position in world coordinates
      Returns:
      a new Vector2 representing the same point in HUD coordinates
    • hudToWorld

      public com.badlogic.gdx.math.Vector2 hudToWorld(com.badlogic.gdx.math.Vector2 hudPos)
      Description copied from interface: HUD
      Converts a position in HUD coordinates to world coordinates.
      Specified by:
      hudToWorld in interface HUD
      Parameters:
      hudPos - the position in HUD coordinates
      Returns:
      a new Vector2 representing the same point in world coordinates
    • worldXtoHUDX

      public float worldXtoHUDX(float worldX)
      Description copied from interface: HUD
      Converts a world X coordinate to HUD X coordinate.
      Specified by:
      worldXtoHUDX in interface HUD
      Parameters:
      worldX - the X coordinate in world space
      Returns:
      the corresponding X coordinate in HUD space
    • worldYtoHUDY

      public float worldYtoHUDY(float worldY)
      Description copied from interface: HUD
      Converts a world Y coordinate to HUD Y coordinate.
      Specified by:
      worldYtoHUDY in interface HUD
      Parameters:
      worldY - the Y coordinate in world space
      Returns:
      the corresponding Y coordinate in HUD space
    • hudXtoWorldX

      public float hudXtoWorldX(float hudX)
      Description copied from interface: HUD
      Converts a HUD X coordinate to world X coordinate.
      Specified by:
      hudXtoWorldX in interface HUD
      Parameters:
      hudX - the X coordinate in HUD space
      Returns:
      the corresponding X coordinate in world space
    • hudYtoWorldY

      public float hudYtoWorldY(float hudY)
      Description copied from interface: HUD
      Converts a HUD Y coordinate to world Y coordinate.
      Specified by:
      hudYtoWorldY in interface HUD
      Parameters:
      hudY - the Y coordinate in HUD space
      Returns:
      the corresponding Y coordinate in world space
    • resize

      public void resize(int width, int height)
      Updates the HUD viewport when the window is resized.
      Specified by:
      resize in interface com.badlogic.gdx.Screen
      Overrides:
      resize in class GameScreen
      Parameters:
      width - the new window width in pixels
      height - the new window height in pixels
    • renderUI

      public void renderUI()
      Description copied from interface: HUD
      Call this method in your render method to render a User Interface. Can only be done when the HUD is enabled.
      Specified by:
      renderUI in interface HUD
    • onUIInteraction

      public void onUIInteraction(String key, Object value)
      Called by GameApp when a UI element is interacted with. Subclasses can override to handle interactions.
      Specified by:
      onUIInteraction in interface HUD
      Parameters:
      key - Name of the element
      value - Value of the element
    • isHUDEnabled

      public boolean isHUDEnabled()
      Description copied from interface: HUD
      Returns true if the HUD is currently enabled.
      Specified by:
      isHUDEnabled in interface HUD
    • getUIStage

      public com.badlogic.gdx.scenes.scene2d.Stage getUIStage()
      Description copied from interface: HUD
      Get the UI stage for adding UI elements
      Specified by:
      getUIStage in interface HUD
      Returns:
      Stage for UI elements