Package nl.saxion.gameapp.screens
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
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidenableHUD(int width, int height) Initializes the HUD with a fixed size.com.badlogic.gdx.graphics.OrthographicCameraReturns theOrthographicCameraused for rendering the HUD.floatReturns the height of the HUD in world units or pixels, depending on the implementation.com.badlogic.gdx.utils.viewport.FitViewportReturns theFitViewportused by the HUD.floatReturns the width of the HUD in world units or pixels, depending on the implementation.com.badlogic.gdx.math.Vector2Returns the current mouse position in HUD coordinates.floatReturns the mouse's X coordinate in HUD space.floatReturns the mouse's Y coordinate in HUD space.com.badlogic.gdx.scenes.scene2d.StageGet the UI stage for adding UI elementscom.badlogic.gdx.math.Vector2hudToWorld(com.badlogic.gdx.math.Vector2 hudPos) Converts a position in HUD coordinates to world coordinates.floathudXtoWorldX(float hudX) Converts a HUD X coordinate to world X coordinate.floathudYtoWorldY(float hudY) Converts a HUD Y coordinate to world Y coordinate.booleanReturns true if the HUD is currently enabled.voidonUIInteraction(String key, Object value) Called by GameApp when a UI element is interacted with.voidrenderUI()Call this method in your render method to render a User Interface.voidresize(int width, int height) Updates the HUD viewport when the window is resized.voidSwitches the rendering context to the HUD.voidSwitches the rendering context from the HUD to the main game world.com.badlogic.gdx.math.Vector2worldToHUD(com.badlogic.gdx.math.Vector2 worldPos) Converts a position in world coordinates to HUD coordinates.floatworldXtoHUDX(float worldX) Converts a world X coordinate to HUD X coordinate.floatworldYtoHUDY(float worldY) Converts a world Y coordinate to HUD Y coordinate.Methods inherited from class nl.saxion.gameapp.screens.GameScreen
dispose, keyDown, keyTyped, keyUp, mouseMoved, pause, render, resume, scrolled, touchCancelled, touchDown, touchDragged, touchUpMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.badlogic.gdx.Screen
hide, showMethods inherited from interface nl.saxion.gameapp.screens.extensions.WorldSize
getMouseWorldPosition, getMouseX, getMouseY, getWorldCamera, getWorldHeight, getWorldWidth
-
Constructor Details
-
GameScreenWithHUD
public GameScreenWithHUD()
-
-
Method Details
-
enableHUD
public void enableHUD(int width, int height) Initializes the HUD with a fixed size. -
getHUDWidth
public float getHUDWidth()Description copied from interface:HUDReturns the width of the HUD in world units or pixels, depending on the implementation.- Specified by:
getHUDWidthin interfaceHUD- Returns:
- the HUD width
-
getHUDHeight
public float getHUDHeight()Description copied from interface:HUDReturns the height of the HUD in world units or pixels, depending on the implementation.- Specified by:
getHUDHeightin interfaceHUD- Returns:
- the HUD height
-
getHUDViewport
public com.badlogic.gdx.utils.viewport.FitViewport getHUDViewport()Description copied from interface:HUDReturns theFitViewportused by the HUD.The viewport ensures consistent scaling and aspect ratio across different screen resolutions.
- Specified by:
getHUDViewportin interfaceHUD- Returns:
- the HUD's
FitViewport
-
getHUDCamera
public com.badlogic.gdx.graphics.OrthographicCamera getHUDCamera()Description copied from interface:HUDReturns theOrthographicCameraused for rendering the HUD.The camera typically operates in an orthographic projection to simplify 2D rendering of HUD elements.
- Specified by:
getHUDCamerain interfaceHUD- Returns:
- the HUD's
OrthographicCamera
-
switchToWorldRendering
public void switchToWorldRendering()Description copied from interface:HUDSwitches the rendering context from the HUD to the main game world.Implementations typically call
batch.setProjectionMatrix(worldCamera.combined)or equivalent logic.- Specified by:
switchToWorldRenderingin interfaceHUD
-
switchToHudRendering
public void switchToHudRendering()Description copied from interface:HUDSwitches the rendering context to the HUD.Implementations typically call
batch.setProjectionMatrix(hudCamera.combined)or equivalent logic before drawing HUD elements.- Specified by:
switchToHudRenderingin interfaceHUD
-
getMouseHUDPosition
public com.badlogic.gdx.math.Vector2 getMouseHUDPosition()Description copied from interface:HUDReturns the current mouse position in HUD coordinates.This can be useful for detecting interactions with UI components or buttons within the HUD.
- Specified by:
getMouseHUDPositionin interfaceHUD- Returns:
- a
Vector2representing the mouse position in HUD space
-
getMouseHUDX
public float getMouseHUDX()Description copied from interface:HUDReturns the mouse's X coordinate in HUD space.- Specified by:
getMouseHUDXin interfaceHUD- Returns:
- the X coordinate of the mouse in HUD coordinates
-
getMouseHUDY
public float getMouseHUDY()Description copied from interface:HUDReturns the mouse's Y coordinate in HUD space.- Specified by:
getMouseHUDYin interfaceHUD- 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:HUDConverts a position in world coordinates to HUD coordinates.- Specified by:
worldToHUDin interfaceHUD- Parameters:
worldPos- the position in world coordinates- Returns:
- a new
Vector2representing the same point in HUD coordinates
-
hudToWorld
public com.badlogic.gdx.math.Vector2 hudToWorld(com.badlogic.gdx.math.Vector2 hudPos) Description copied from interface:HUDConverts a position in HUD coordinates to world coordinates.- Specified by:
hudToWorldin interfaceHUD- Parameters:
hudPos- the position in HUD coordinates- Returns:
- a new
Vector2representing the same point in world coordinates
-
worldXtoHUDX
public float worldXtoHUDX(float worldX) Description copied from interface:HUDConverts a world X coordinate to HUD X coordinate.- Specified by:
worldXtoHUDXin interfaceHUD- 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:HUDConverts a world Y coordinate to HUD Y coordinate.- Specified by:
worldYtoHUDYin interfaceHUD- 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:HUDConverts a HUD X coordinate to world X coordinate.- Specified by:
hudXtoWorldXin interfaceHUD- 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:HUDConverts a HUD Y coordinate to world Y coordinate.- Specified by:
hudYtoWorldYin interfaceHUD- 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:
resizein interfacecom.badlogic.gdx.Screen- Overrides:
resizein classGameScreen- Parameters:
width- the new window width in pixelsheight- the new window height in pixels
-
renderUI
public void renderUI()Description copied from interface:HUDCall this method in your render method to render a User Interface. Can only be done when the HUD is enabled. -
onUIInteraction
Called by GameApp when a UI element is interacted with. Subclasses can override to handle interactions.- Specified by:
onUIInteractionin interfaceHUD- Parameters:
key- Name of the elementvalue- Value of the element
-
isHUDEnabled
public boolean isHUDEnabled()Description copied from interface:HUDReturns true if the HUD is currently enabled.- Specified by:
isHUDEnabledin interfaceHUD
-
getUIStage
public com.badlogic.gdx.scenes.scene2d.Stage getUIStage()Description copied from interface:HUDGet the UI stage for adding UI elements- Specified by:
getUIStagein interfaceHUD- Returns:
- Stage for UI elements
-