Class GameApp
Typical usage involves calling start(String, int, int, int, boolean, String) to
initialize the game and then using switchScreen(String) to transition between
different game screens.
Example:
public class MyGame {
public static void main(String[] args) {
GameApp.start("My Game", 1280, 720, 60, false, "MainMenu");
}
}
Screens must be registered before switching, typically through a static registration method or within the game's initialization logic.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classInner class that extends the Game object of LibGDX Used for initializing the game and loading the first screen. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddAnimation(String name, com.badlogic.gdx.graphics.g2d.TextureRegion[] frames, float frameDuration, boolean loop) Adds a new animation using manually specified frames.static voidaddAnimationFrameFromAtlas(String animationName, String atlasName, String regionName) Adds a single region from an atlas to an existing animation.static voidaddAnimationFrameFromSpritesheet(String animationName, String spritesheet, int row, int col) Adds a single frame from a spritesheet (by row and column) to an existing animation.static voidaddAnimationFromAtlas(String name, String atlasName, String prefix, float frameDuration, boolean loop) Creates a new animation using all regions in a given atlas that match a prefix.static voidaddAnimationFromSpritesheet(String name, String spritesheet, float frameDuration, boolean loop) Adds a new animation using all frames from the specified spritesheet.static voidAdds aTextButtonto the currently active HUD.static voidaddCheckBox(String name, String skinName, float x, float y, String text, boolean checked) Adds aCheckBoxto the currently active HUD.static voidAdds a named color to the global registry using RGB components (0-255) with full opacity.static voidAdds a named color to the global registry using RGBA components (0-255).static voidAdds a namedColorto the global color registry.static voidaddCustomUIComponent(String name, com.badlogic.gdx.scenes.scene2d.Actor uiComponent) Adds a custom LibGDXActorto the currently active HUD.static voidaddEmptyAnimation(String name, float frameDuration, boolean loop) Creates an empty animation with a given frame duration and loop flag.static voidRegisters an already createdBitmapFontunder a given name.static voidOverload: Adds a font that scales to world height by default.static voidLoads a TTF or OTF font, optionally scaling it to world height or keeping pixel size.static voidaddInterpolator(String name, float start, float end, float duration, com.badlogic.gdx.math.Interpolation strategy) Creates a new interpolator with the given name.static voidaddInterpolator(String name, float start, float end, float duration, String strategy) Creates a new interpolator with the given name.static voidaddItemToStore(String name, Object anyType) Add item to the application store, so that it can be used in multiple screens.static voidAdds a staticLabelto the currently active HUD.static voidLoads and stores a music track from a file path under the given name.static voidaddParticleEffect(String name, String filePath) Load a particle effect and create a pool for it.static voidaddProgressBar(String name, String skinName, float x, float y, float width, float height, float min, float max, boolean vertical, float value) Adds aProgressBarto the currently active HUD.static voidRegister a screen with a unique name.static voidaddSelectBox(String name, String skinName, float x, float y, float width, float height, String... items) Adds aSelectBox(drop-down menu) to the currently active HUD.static voidAdds a skin to the internal skin registry by loading it from a JSON file.static voidaddSlider(String name, String skinName, float x, float y, float width, float height, float min, float max, float step, boolean vertical) Adds aSliderto the currently active HUD.static voidLoads and stores a sound effect from a file path under the given name.static voidaddSpriteSheet(String name, String filePath, int frameWidth, int frameHeight) Loads a spritesheet from a file, slices it into frames, and stores the frames.static voidaddStyledFont(String name, String filePath, int size, com.badlogic.gdx.graphics.Color color, float borderWidth, com.badlogic.gdx.graphics.Color borderColor, int shadowOffsetX, int shadowOffsetY, com.badlogic.gdx.graphics.Color shadowColor, boolean usePixelSize) Loads a styled TTF font with optional border and shadow, with world-scaling or pixel-perfect option.static voidaddStyledFont(String name, String filePath, int size, String colorName, float borderWidth, String borderColorName, int shadowOffsetX, int shadowOffsetY, String shadowColorName, boolean usePixelSize) Styled font with named colors (throws if color names not found).static voidaddTextField(String name, String skinName, float x, float y, float width, float height, String messageText) Adds aTextField(input box) to the currently active HUD.static voidaddTexture(String name, String filePath) Loads a texture from a file path and stores it in the global texture registry.static voidaddTexture(String name, String filePath, com.badlogic.gdx.graphics.Texture.TextureFilter filter) Loads a texture from a file path and stores it in the global texture registry.static voidaddTexture(String name, String filePath, com.badlogic.gdx.graphics.Texture.TextureFilter minFilter, com.badlogic.gdx.graphics.Texture.TextureFilter maxFilter) Loads a texture from a file path and stores it in the global texture registry.static voidaddTextureAtlas(String name, String filePath) Loads a texture atlas and stores it in the internal atlas map.static voidAdd a timer with simple looping boolean.static voidAdd a timer.static floatangleBetween(float x1, float y1, float x2, float y2) Calculates the angle in degrees from the first point to the second point.static voidassertCondition(boolean condition, String message) Checks a condition and prints a message if it fails.static booleancircleOverlap(float x1, float y1, float r1, float x2, float y2, float r2) Checks if two circles overlap.static booleancircleOverlap(com.badlogic.gdx.math.Circle c1, com.badlogic.gdx.math.Circle c2) static floatclamp(float value, float min, float max) Clamps a value to be within the specified minimum and maximum range.static voidClears the mask completely.static voidClears the screen to black (0, 0, 0).static voidclearScreen(int r, int g, int b) Clears the screen to the specified RGB color.static voidclearScreen(com.badlogic.gdx.graphics.Color color) Clears the screen using the specifiedColor.static voidclearScreen(String colorName) Clears the screen using a named color from the color registry.static GameApp.GameImplcreateCrossPlatformGame(String firstScreenName) Creates a new GameImpl instance for cross-platform backends (Android, iOS, WebGL).static voidPrints multiple values in a single line.static voidDisable transparency for shape render and sprite batch.static voiddisposeAnimation(String name) Removes an animation.static voiddisposeAtlas(String name) Removes the atlas and disposes it from memory.static voiddisposeFont(String name) Remove the font and unload it from the memory.static voiddisposeInterpolator(String name) Removes an interpolator from the internal registry.static voiddisposeMusic(String name) Remove the music and unload it from the memory.static voiddisposeParticleEffect(String name) Remove the particle effect by name.static voiddisposeSkin(String key) Disposes of a skin in the registry.static voiddisposeSound(String name) Remove the sound and unload it from the memory.static voiddisposeSpritesheet(String name) Removes the spritesheet and disposes its underlying Texture.static voiddisposeTexture(String name) Remove the texture and unload it from the memory.static voiddisposeTimer(String name) Dispose of timer.static voidRemoves all UI elements from the current HUD stage.static floatdistance(float x1, float y1, float x2, float y2) Calculates the distance between two points.static voiddrawAnimation(String name, float x, float y) Draws the current frame of the animation at the specified bottom-left position.static voiddrawAnimation(String name, float x, float y, float width, float height) Draws the current frame of the animation at the specified position and size.static voiddrawAnimation(String name, float x, float y, float width, float height, float rotationDegrees, boolean flipX, boolean flipY) Draws the current frame of the animation at the specified position, size, rotation, and flipping.static voiddrawAnimationCentered(String name, float centerX, float centerY) Draws the current frame of the animation centered at the specified position.static voiddrawAnimationCentered(String name, float centerX, float centerY, float width, float height) Draws the current frame of the animation centered at the specified position with the given size.static voiddrawAnimationCentered(String name, float centerX, float centerY, float width, float height, float rotationDegrees, boolean flipX, boolean flipY) Draws the current frame of the animation centered at the specified position with size, rotation, and flipping.static voiddrawAtlasRegion(String atlasName, String regionName, float x, float y) Draws a region from an atlas at the specified position.static voiddrawAtlasRegion(String atlasName, String regionName, float x, float y, float width, float height) Draws a region from an atlas at the specified position with scaling.static voiddrawAtlasRegion(String atlasName, String regionName, float x, float y, float width, float height, float rotationDegrees, boolean flipX, boolean flipY) Draws a region from an atlas at the specified position with scaling, rotation, and flipping.static voiddrawAtlasRegionCentered(String atlasName, String regionName, float centerX, float centerY) Draws a region from an atlas centered at a given position.static voiddrawAtlasRegionCentered(String atlasName, String regionName, float centerX, float centerY, float width, float height) Draws a region from an atlas centered with scaling.static voiddrawAtlasRegionCentered(String atlasName, String regionName, float centerX, float centerY, float width, float height, float rotationDegrees, boolean flipX, boolean flipY) Draws a region from an atlas centered with scaling, rotation, and flipping.static voiddrawCircle(float x, float y, float radius) Draws a circle.static voiddrawCircle(float x, float y, float radius, int segments) Draws a circle with a specified number of segments.static voiddrawCircle(float x, float y, float radius, int segments, com.badlogic.gdx.graphics.Color color) Draws a circle in a specific color with a specified number of segments.static voiddrawCircle(float x, float y, float radius, int segments, String colorName) Draws a circle in a specific color with a specified number of segments.static voiddrawCircle(float x, float y, float radius, com.badlogic.gdx.graphics.Color color) Draws a circle in a specific color.static voiddrawCircle(float x, float y, float radius, String colorName) Draws a circle in a specific color.static voiddrawEllipse(float x, float y, float width, float height) Draws an ellipse.static voiddrawEllipse(float x, float y, float width, float height, com.badlogic.gdx.graphics.Color color) Draws an ellipse in a specific color.static voiddrawEllipse(float x, float y, float width, float height, String colorName) Draws an ellipse in a specific color.static voiddrawEllipseCentered(float centerX, float centerY, float width, float height) Draws an ellipse centered on a specified point.static voiddrawEllipseCentered(float centerX, float centerY, float width, float height, com.badlogic.gdx.graphics.Color color) Draws an ellipse centered on a specified point with a Color object.static voiddrawEllipseCentered(float centerX, float centerY, float width, float height, String colorName) Draws an ellipse centered on a specified point with a color name.static voiddrawLine(float x1, float y1, float x2, float y2) Draws a line.static voiddrawLine(float x1, float y1, float x2, float y2, com.badlogic.gdx.graphics.Color color) Draws a line in a specific color.static voidDraws a line in a specific color.static voiddrawPolygon(float[] vertices) Draws a polygon.static voiddrawPolygon(float[] vertices, com.badlogic.gdx.graphics.Color color) Draws a polygon in a specific color.static voiddrawPolygon(float[] vertices, String colorName) Draws a polygon in a specific color.static voiddrawRect(float x, float y, float width, float height) Draws a rectangle.static voiddrawRect(float x, float y, float width, float height, com.badlogic.gdx.graphics.Color color) Draws a rectangle in a specific color.static voidDraws a rectangle in a specific color.static voiddrawRectCentered(float centerX, float centerY, float width, float height) Draws a rectangle centered on a specified point.static voiddrawRectCentered(float centerX, float centerY, float width, float height, com.badlogic.gdx.graphics.Color color) Draws a rectangle centered on a specified point with a Color object.static voiddrawRectCentered(float centerX, float centerY, float width, float height, String colorName) Draws a rectangle centered on a specified point with a color name.static voiddrawRoundedRect(float x, float y, float width, float height, float radius) Draws a rounded rectangle using the class's ShapeRenderer.static voiddrawRoundedRect(float x, float y, float width, float height, float radius, com.badlogic.gdx.graphics.Color color) Draws a rounded rectangle with a specified Color object.static voiddrawRoundedRect(float x, float y, float width, float height, float radius, String colorName) Draws a rounded rectangle with a specified color name.static voiddrawRoundedRectCentered(float centerX, float centerY, float width, float height, float radius) Draws a rounded rectangle centered on a specified point.static voiddrawRoundedRectCentered(float centerX, float centerY, float width, float height, float radius, com.badlogic.gdx.graphics.Color color) Draws a rounded rectangle centered on a specified point with a Color object.static voiddrawRoundedRectCentered(float centerX, float centerY, float width, float height, float radius, String colorName) Draws a rounded rectangle centered on a specified point with a color name.static voiddrawSpritesheetFrame(String name, int row, int col, float x, float y) Draw a specific frame from a spritesheet at the given position.static voiddrawSpritesheetFrame(String name, int row, int col, float x, float y, float width, float height) Draw a specific frame with scaling.static voiddrawSpritesheetFrame(String name, int row, int col, float x, float y, float width, float height, float rotationDegrees, boolean flipX, boolean flipY) Draw a specific frame with scaling, rotation, and flipping.static voiddrawSpritesheetFrameCentered(String name, int row, int col, float centerX, float centerY) Draw a frame centered at a given position.static voiddrawSpritesheetFrameCentered(String name, int row, int col, float centerX, float centerY, float width, float height) Draw a frame centered with scaling.static voiddrawSpritesheetFrameCentered(String name, int row, int col, float centerX, float centerY, float width, float height, float rotationDegrees, boolean flipX, boolean flipY) Draw a frame centered with scaling, rotation, and flipping.static voidDraws text left-bottom aligned at the specified position with a given color.static voidDraws text left-bottom aligned at the specified position with a given color.static voiddrawTextCentered(String fontName, String text, float centerX, float centerY, com.badlogic.gdx.graphics.Color color) Draws text centered on a specified point with a given color.static voiddrawTextCentered(String fontName, String text, float centerX, float centerY, String color) Draws text centered on a specified point with a given color.static voiddrawTextHorizontallyCentered(String fontName, String text, float centerX, float y, com.badlogic.gdx.graphics.Color color) Draws text horizontally centered at a given X-coordinate with a given Y-coordinate and color.static voiddrawTextHorizontallyCentered(String fontName, String text, float centerX, float y, String color) Overload with color as string.static voiddrawTexture(String name, float x, float y) Draws a texture at the specified position using the current sprite batch.static voiddrawTexture(String name, float x, float y, float width, float height) Draws a texture at the specified position and size using the current sprite batch.static voiddrawTexture(String name, float x, float y, float width, float height, float rotationDegrees, boolean flipX, boolean flipY) Draws a texture at the specified position, size, rotation, and flipping using the current sprite batch.static voiddrawTextureCentered(String name, float centerX, float centerY) Draws a texture centered at the specified position using the current sprite batch.static voiddrawTextureCentered(String name, float centerX, float centerY, float width, float height) Draws a texture centered at the specified position with size using the current sprite batch.static voiddrawTextureCentered(String name, float centerX, float centerY, float width, float height, float rotationDegrees, boolean flipX, boolean flipY) Draws a texture centered at the specified position with size, rotation, and flipping using the current sprite batch.static voiddrawTextVerticallyCentered(String fontName, String text, float x, float centerY, com.badlogic.gdx.graphics.Color color) Draws text vertically centered at a given Y-coordinate with a given X-coordinate and color.static voiddrawTextVerticallyCentered(String fontName, String text, float x, float centerY, String color) Overload with color as string.static voidEnable transparency for shape render and sprite batch.static voidendMask()Ends the mask definition and applies it to subsequent drawing.static voidEnds the current shape rendering batch.static voidEnds the current sprite rendering batch.static voidPrints an error message in red.static booleanfileExists(String fileName) Checks if the save file exists.static long[]Get a list with all active particle id'sstatic String[]Get the names of all registered colors.static SpriteAnimationgetAnimation(String name) Retrieves an animation by name.static intReturns the index of the current frame of the named animation.static intgetAnimationFrameCount(String name) Returns the total number of frames in the named animation.static com.badlogic.gdx.graphics.g2d.TextureAtlasGet the texture atlas object.static com.badlogic.gdx.graphics.g2d.TextureRegiongetAtlasRegion(String atlasName, String regionName) Retrieves aTextureRegionfrom a loaded texture atlas.static booleangetCheckBoxValue(String name) Returns whether aCheckBoxis currently checked.static com.badlogic.gdx.graphics.ColorRetrieves a namedColorfrom the global color registry.static com.badlogic.gdx.ScreenReturns the currently activeScreenof the game.static StringGet the name of the current screen.static floatReturns the time elapsed since the last frame, in seconds.static com.badlogic.gdx.graphics.g2d.BitmapFontRetrieves a loaded font by its name.static intReturns the current frame rate of the application, in frames per second (FPS).static String[]Get a list of all the possible interpolation strategies availablestatic InterpolatorgetInterpolator(String name) Retrieves an existing interpolator by name.static ObjectgetItemFromStore(String name) Get an item from the application store by name.static StringgetLabelValue(String name) Returns the text of aLabel.static com.badlogic.gdx.GameWARNING: using this object can heavily influence the behaviour of the GameApp.static com.badlogic.gdx.math.Vector2Returns the current position of the mouse in screen coordinates as aVector2.static intReturns the current X-coordinate of the mouse cursor in screen coordinates.static intReturns the current Y-coordinate of the mouse cursor in screen coordinates.static com.badlogic.gdx.audio.Musicstatic com.badlogic.gdx.graphics.g2d.ParticleEffectPoolgetParticleEffectPool(String name) Only for advanced users: get the particle pool object from the app directly.static floatgetProgressBarValue(String name) Retrieves the current value of aProgressBaron the active HUD.static String[]Get a list with all screen names that are definedstatic StringgetSelectBoxValue(String name) Returns the currently selected item of aSelectBox.static com.badlogic.gdx.graphics.glutils.ShapeRendererReturns the sharedShapeRendererinstance used for rendering shapes.static com.badlogic.gdx.scenes.scene2d.ui.SkinRetrieves a skin from the registry by its key.static floatgetSliderValue(String name) Returns the current value of aSlider.static com.badlogic.gdx.audio.Soundstatic com.badlogic.gdx.graphics.g2d.SpriteBatchReturns the sharedSpriteBatchinstance used for rendering sprites.static com.badlogic.gdx.graphics.g2d.TextureRegiongetSpritesheetFrame(String name, int row, int col) Retrieve a specific frame from a spritesheet.static intReturns the number of columns in the specified spritesheet.static intReturns the number of rows in the specified spritesheet.static StringgetTextFieldValue(String name) Returns the current text of aTextField.static floatgetTextHeight(String fontName, String text) Returns the height of a given text in pixels when rendered with the specified font.static com.badlogic.gdx.graphics.TexturegetTexture(String name) Retrieves a texture from the global texture registry by name.static intgetTextureHeight(String name) Returns the height in pixels of the texture with the given name.static intgetTextureWidth(String name) Returns the width in pixels of the texture with the given name.static floatgetTextWidth(String fontName, String text) Returns the width of a given text in pixels when rendered with the specified font.static TimerRetrieve timer object.static floatgetTimerRemaining(String name) Get remaining time until next trigger.static com.badlogic.gdx.scenes.scene2d.ActorgetUIElement(String name) Retrieves the raw LibGDXActorfor a given UI element key.static intReturns the current height of the game window in pixels.static intReturns the current width of the game window in pixels.static floatGet the height of the world (this method is identical to calling getWorldWidth() in your own screen object)static floatGet the width of the world (this method is identical to calling getWorldWidth() in your own screen object)static booleanhasAnimation(String name) Checks if an animation exists.static booleanReturns if an atlas is available with the given namestatic booleanChecks whether a color with the given name exists in the global registry.static booleanReturns if font is available with the given namestatic booleanhasInterpolator(String name) Checks whether an interpolator with the given name exists.static booleanhasItemInStore(String name) Check if an item exists with the given namestatic booleanReturns if music is available with the given namestatic booleanhasParticleEffect(String name) Checks whether a particle effect pool exists for the given name.static booleanChecks whether a skin exists in the registry.static booleanReturns if a sound is available with the given namestatic booleanhasSpritesheet(String name) Returns if a spritesheet is available with the given name.static booleanhasTexture(String name) Returns if texture is available with the given namestatic booleanReturns true if a timer exists.static booleanhasUIElement(String name) Checks whether a UI element with the given key exists in the currently active HUD.static voidHides the system mouse cursor.static voidInverts the mask effect.static booleanisAnimationFinished(String name) Checks if the animation has finished.static booleanisButtonJustPressed(int button) Returns true if the specified mouse button was just pressed this frame.static booleanisButtonPressed(int button) Returns true if the specified mouse button is currently held down.static booleanChecks if the game is currently in fullscreen mode.static booleanisInterpolatorFinished(String name) Checks whether the interpolator has finished its animation.static booleanisKeyJustPressed(int keyCode) Returns true if the specified key was just pressed this frame.static booleanisKeyPressed(int keyCode) Returns true if the specified key is currently held down.static booleanChecks if the particle effect instance has finishedstatic booleanisTimerFinished(String name) Checks whether a timer has finished all its loops.static voidjumpAnimationToFrame(String name, int frameIndex) Jumps the named animation to a specific frame.static ObjectloadFromBinary(String fileName) Loads any object from a binary file.static <T> TloadFromJson(String fileName, Class<T> type) Load an object from a JSON file.static voidPrints a simple message to the console.static voidPrints a variable with its name for easier debugging.static float[]moveInDirection(float x, float y, float distance, float directionDegrees) Computes new coordinates by moving from a starting point in a specified direction and distance.static voidpauseTimer(String name) Pause timer.static voidPlays a music track, optionally looping.static voidPlays a music track, optionally looping with a specific volume.static longPlays a sound effect at full volume (1.0).static longPlays a sound effect at the specified volume.static booleanpointInCircle(float px, float py, float cx, float cy, float radius) Checks if a point is inside a circle.static booleanpointInCircle(com.badlogic.gdx.math.Vector2 point, com.badlogic.gdx.math.Circle circle) static booleanpointInRect(float px, float py, float rx, float ry, float rw, float rh) Checks if a point is inside a rectangle.static booleanpointInRect(com.badlogic.gdx.math.Vector2 point, com.badlogic.gdx.math.Rectangle rect) static voidquit()Exits the game application.static floatrandom(float min, float max) Returns a random float value within the specified range.static <T> TReturns a random element from a List of any type.static <T> Trandom(T[] array) Returns a random element from an array.static intrandomInt(int min, int max) Returns a random int value within the specified range.static booleanrectCircleOverlap(float rectX, float rectY, float rectW, float rectH, float circleX, float circleY, float radius) Checks if an axis-aligned rectangle and a circle overlap.static booleanrectCircleOverlap(com.badlogic.gdx.math.Rectangle rect, com.badlogic.gdx.math.Circle circle) static booleanrectContainsRect(float x1, float y1, float w1, float h1, float x2, float y2, float w2, float h2) Checks if one rectangle is completely contained within another rectangle.static booleanrectContainsRect(com.badlogic.gdx.math.Rectangle outer, com.badlogic.gdx.math.Rectangle inner) static booleanrectOverlap(float x1, float y1, float w1, float h1, float x2, float y2, float w2, float h2) Checks if two axis-aligned rectangles overlap.static booleanrectOverlap(com.badlogic.gdx.math.Rectangle r1, com.badlogic.gdx.math.Rectangle r2) static booleanremoveItemFromStore(String name) Remove an item from the store by name.static voidDraw one specific particle effect instance.static voidRender all active particle effects using GameApp.spriteBatch.static voidresetAnimation(String name) Resets an animation to start from the beginning.static voidresetAnimation(String name, boolean reverse) Resets an animation to start from the beginning, optionally reversing it.static voidresetInterpolator(String name) Resets the interpolator with the given name to start its animation from the beginning.static voidresetInterpolator(String name, boolean reverse) Resets the interpolator with the given name to start its animation from the beginning.static voidresetTimer(String name) Reset timer to initial state.static voidresumeTimer(String name) Resume timer.static voidsaveToBinary(Object object, String fileName) Saves any object to a binary file.static voidsaveToJson(Object object, String fileName) Serialize any object to JSON and save to a file.static voidsetCheckBoxValue(String name, boolean checked) Sets the checked state of aCheckBox.static voidsetColor(int r, int g, int b) Sets the current drawing color using RGB components (0-255) with full opacity.static voidsetColor(int r, int g, int b, int a) Sets the current drawing color using RGBA components (0-255).static voidsetColor(com.badlogic.gdx.graphics.Color color) Sets the current drawing color for shapes.static voidSets the current drawing color using a registered color name.static voidsetCustomCursor(String filePath, int hotspotX, int hotspotY) Sets a custom cursor image from a file.static voidsetFPS(int fps) Sets the target frames per second (FPS) for rendering.static voidsetLabelValue(String name, String value) Sets the text of aLabel.static voidsetLineWidth(float width) Set the width of the outline when drawing with the shape renderer.static voidsetProgressBarValue(String name, float value) Sets the value of aProgressBaron the active HUD.static voidsetResizable(boolean resizable) Sets whether the game window can be resized by the user.static voidsetSelectBoxValue(String name, String value) Sets the selected item of aSelectBox.static voidsetSliderValue(String name, float value) Sets the value of aSlider.static voidsetSystemCursor(com.badlogic.gdx.graphics.Cursor.SystemCursor systemCursor) Sets the system cursor to one of the default cursors.static voidsetTextFieldValue(String name, String value) Sets the text of aTextField.static voidsetTimerDuration(String name, float newDuration) Change timer duration.static voidChanges the title of the game window.static voidsetVSync(boolean vsync) Enables or disables vertical synchronization (VSync).static voidShows the default system mouse cursor.static longspawnParticleEffect(String name, float x, float y) Spawn a particle effect at a position.static voidConfigure the game application and start it immediately.static voidStarts a new mask definition.static voidBegins shape rendering in filled mode.static voidBegins shape rendering in outlined (line) mode.static voidBegins shape rendering in point mode.static voidBegins sprite rendering.static voidClears all active effects and returns them to their pools.static voidStops all audio, including sound effects and music.static voidStops all currently playing music tracks.static voidStops all currently playing sound effects.static voidStops a specific music track by name.static voidstopParticleEffect(long id) Stop a specific active particle effect.static voidstopSound(long soundId) Stops a specific sound effect by its playback ID.static voidswitchScreen(String name) Switches the currently active screen in the game to the one specified by name.static voidSwitches the game window to fullscreen mode using the current display mode.static voidswitchToWindowedMode(int width, int height) Switches the game window to windowed mode with the specified width and height.static booleantimerWentOff(String name) Query if a timer went off in the last update call.static voidupdateAnimation(String name) Updates the animation by the frame's delta time.static floatupdateInterpolator(String name) Updates the interpolator with the given name and returns the current value.static voidUpdate all active particle effects.static voidupdateTimer(String name) Update single timer using Gdx deltaTime.static voidUpdate all timers using Gdx deltaTime.static voidPrints a warning message in yellow.
-
Constructor Details
-
GameApp
public GameApp()
-
-
Method Details
-
start
public static void start(String title, int width, int height, int fps, boolean fullScreen, String firstScreenName) Configure the game application and start it immediately.Developer info: This method creates and launches a new
Lwjgl3Applicationinstance using the provided title, resolution, frame rate, and display mode settings. The game begins by displaying the screen identified byfirstScreenName.- Parameters:
title- the title of the game windowwidth- the width of the game window in pixelsheight- the height of the game window in pixelsfps- the target frames per second (FPS) for renderingfullScreen-trueto start the game in fullscreen mode;falsefor windowed modefirstScreenName- the name of the first screen to display when the game starts- Throws:
IllegalStateException- if the game has already been started
-
createCrossPlatformGame
Creates a new GameImpl instance for cross-platform backends (Android, iOS, WebGL). Screens must be registered separately before starting the game.- Parameters:
firstScreenName- the name of the first screen to display- Returns:
- the created GameImpl instance
-
quit
public static void quit()Exits the game application.This method signals LibGDX to terminate the application and close the game window. Any cleanup logic in
ApplicationListener.dispose()will be executed. -
switchToFullscreen
public static void switchToFullscreen()Switches the game window to fullscreen mode using the current display mode.This method only works on desktop platforms using the Lwjgl3 backend.
-
switchToWindowedMode
public static void switchToWindowedMode(int width, int height) Switches the game window to windowed mode with the specified width and height.This method only works on desktop platforms using the Lwjgl3 backend.
- Parameters:
width- the width of the window in pixelsheight- the height of the window in pixels- Throws:
RuntimeException- if the current backend does not support windowed mode changes
-
setResizable
public static void setResizable(boolean resizable) Sets whether the game window can be resized by the user.This method only works on desktop platforms using the Lwjgl3 backend.
- Parameters:
resizable-trueto allow resizing,falseto disable- Throws:
RuntimeException- if the current backend does not support changing resizable property
-
setTitle
Changes the title of the game window.This method only works on desktop platforms using the Lwjgl3 backend.
- Parameters:
title- the new window title- Throws:
RuntimeException- if the current backend does not support changing the window title
-
isFullscreen
public static boolean isFullscreen()Checks if the game is currently in fullscreen mode.This method only works on desktop platforms using the Lwjgl3 backend.
- Returns:
trueif the game is fullscreen,falseotherwise- Throws:
RuntimeException- if the current backend does not support fullscreen mode detection
-
setFPS
public static void setFPS(int fps) Sets the target frames per second (FPS) for rendering.This method only works on desktop platforms. Changing the FPS dynamically can help reduce CPU/GPU usage or control the speed of the game loop.
- Parameters:
fps- the target frames per second (must be > 0)- Throws:
IllegalArgumentException- iffpsis not positive
-
setVSync
public static void setVSync(boolean vsync) Enables or disables vertical synchronization (VSync).When VSync is enabled, the frame rate is synchronized to the monitor's refresh rate to prevent screen tearing. This method only works on desktop platforms.
- Parameters:
vsync-trueto enable VSync,falseto disable
-
addScreen
Register a screen with a unique name.- Parameters:
name- Name of the screenscreen- Screen object
-
getScreenNames
Get a list with all screen names that are defined- Returns:
- Screen names
-
getCurrentScreenName
Get the name of the current screen.- Returns:
- name of the screen or an exception in case it is not found
-
switchScreen
Switches the currently active screen in the game to the one specified by name.- Parameters:
name- the name of the screen to switch to; must correspond to a registered screen- Throws:
IllegalStateException- if the game has not been started yet.IllegalArgumentException- if no screen with the specified name exists.
-
getCurrentScreen
public static com.badlogic.gdx.Screen getCurrentScreen()Returns the currently activeScreenof the game.- Returns:
- the current screen, or
nullif the game has not been started yet
-
getWindowWidth
public static int getWindowWidth()Returns the current width of the game window in pixels. PLEASE NOTE: THIS IT NOT THE WORLD WIDTH- Returns:
- the width of the game window in pixels
-
getWindowHeight
public static int getWindowHeight()Returns the current height of the game window in pixels. PLEASE NOTE: THIS IT NOT THE WORLD HEIGHT- Returns:
- the height of the game window in pixels
-
getWorldWidth
public static float getWorldWidth()Get the width of the world (this method is identical to calling getWorldWidth() in your own screen object)- Returns:
- width of the world
-
getWorldHeight
public static float getWorldHeight()Get the height of the world (this method is identical to calling getWorldWidth() in your own screen object)- Returns:
- height of the world
-
getDeltaTime
public static float getDeltaTime()Returns the time elapsed since the last frame, in seconds.This is equivalent to
Gdx.graphics.getDeltaTime() in LibGDX and is useful for frame rate independent calculations, such as movement or animations.- Returns:
- the delta time in seconds since the last frame
-
getFramesPerSecond
public static int getFramesPerSecond()Returns the current frame rate of the application, in frames per second (FPS).This value is updated by LibGDX each frame and can be used for debugging, performance monitoring, or display in an FPS counter.
- Returns:
- the number of frames rendered in the last second
-
getLibGDXGame
public static com.badlogic.gdx.Game getLibGDXGame()WARNING: using this object can heavily influence the behaviour of the GameApp. This is only useful for advanced users.- Returns:
- The Game object from LibGDX, use to run this application.
-
getMousePositionInWindowX
public static int getMousePositionInWindowX()Returns the current X-coordinate of the mouse cursor in screen coordinates.- Returns:
- the X position of the mouse
-
getMousePositionInWindowY
public static int getMousePositionInWindowY()Returns the current Y-coordinate of the mouse cursor in screen coordinates.- Returns:
- the Y position of the mouse
-
getMousePositionInWindow
public static com.badlogic.gdx.math.Vector2 getMousePositionInWindow()Returns the current position of the mouse in screen coordinates as aVector2.- Returns:
- a new Vector2 containing the mouse coordinates
-
isKeyPressed
public static boolean isKeyPressed(int keyCode) Returns true if the specified key is currently held down.- Parameters:
keyCode- the key code to check (seeInput.Keys)- Returns:
- true if the key is pressed, false otherwise
-
isKeyJustPressed
public static boolean isKeyJustPressed(int keyCode) Returns true if the specified key was just pressed this frame.- Parameters:
keyCode- the key code to check (seeInput.Keys)- Returns:
- true if the key was just pressed, false otherwise
-
isButtonPressed
public static boolean isButtonPressed(int button) Returns true if the specified mouse button is currently held down.- Parameters:
button- the mouse button to check (seeInput.Buttons)- Returns:
- true if the button is pressed, false otherwise
-
isButtonJustPressed
public static boolean isButtonJustPressed(int button) Returns true if the specified mouse button was just pressed this frame.- Parameters:
button- the mouse button to check (seeInput.Buttons)- Returns:
- true if the button was just pressed, false otherwise
-
addSound
Loads and stores a sound effect from a file path under the given name.- Parameters:
name- the name to associate with the soundfilePath- the internal file path of the sound effect
-
addMusic
Loads and stores a music track from a file path under the given name.- Parameters:
name- the name to associate with the musicfilePath- the internal file path of the music track
-
disposeSound
Remove the sound and unload it from the memory.- Parameters:
name- Name of the sound.
-
disposeMusic
Remove the music and unload it from the memory.- Parameters:
name- Name of the music.
-
playSound
Plays a sound effect at the specified volume.- Parameters:
name- the name of the loaded soundvolume- the playback volume (0f - 1f)- Returns:
- the playback ID for the sound instance
- Throws:
IllegalArgumentException- if the sound has not been loaded
-
playSound
Plays a sound effect at full volume (1.0).- Parameters:
name- the name of the loaded sound- Returns:
- the playback ID for the sound instance
- Throws:
IllegalArgumentException- if the sound has not been loaded
-
playMusic
Plays a music track, optionally looping.If the music is already playing, this method does nothing.
- Parameters:
name- the name of the loaded musiclooping-trueto loop the music,falseto play once- Throws:
IllegalArgumentException- if the music has not been loaded
-
playMusic
Plays a music track, optionally looping with a specific volume.If the music is already playing, this method does nothing.
- Parameters:
name- the name of the loaded musiclooping-trueto loop the music,falseto play oncevolume- the playback volume (0f - 1f)- Throws:
IllegalArgumentException- if the music has not been loaded
-
stopSound
public static void stopSound(long soundId) Stops a specific sound effect by its playback ID.- Parameters:
soundId- the playback ID returned byplaySound(String)
-
stopAllSounds
public static void stopAllSounds()Stops all currently playing sound effects. -
stopMusic
Stops a specific music track by name.- Parameters:
name- the name of the loaded music track
-
stopAllMusic
public static void stopAllMusic()Stops all currently playing music tracks. -
stopAllAudio
public static void stopAllAudio()Stops all audio, including sound effects and music. -
getSound
-
getMusic
-
hasSound
Returns if a sound is available with the given name- Parameters:
name- Name of the sound- Returns:
- True, if it exists
-
hasMusic
Returns if music is available with the given name- Parameters:
name- Name of the music- Returns:
- True, if it exists
-
getShapeRenderer
public static com.badlogic.gdx.graphics.glutils.ShapeRenderer getShapeRenderer()Returns the sharedShapeRendererinstance used for rendering shapes.- Returns:
- the global
ShapeRendererinstance
-
addColor
Adds a namedColorto the global color registry.- Parameters:
name- the name to associate with the colorcolor- theColorinstance
-
addColor
Adds a named color to the global registry using RGBA components (0-255).- Parameters:
name- the name to associate with the colorr- red component (0-255)g- green component (0-255)b- blue component (0-255)a- alpha component (0-255)
-
addColor
Adds a named color to the global registry using RGB components (0-255) with full opacity.- Parameters:
name- the name to associate with the colorr- red component (0-255)g- green component (0-255)b- blue component (0-255)
-
getColor
Retrieves a namedColorfrom the global color registry.- Parameters:
name- the name of the color- Returns:
- the
Colorassociated with the name - Throws:
IllegalArgumentException- if the color with the given name does not exist
-
getAllColors
Get the names of all registered colors.- Returns:
- String array with all color names.
-
hasColor
Checks whether a color with the given name exists in the global registry.- Parameters:
name- the name of the color- Returns:
trueif the color exists,falseotherwise
-
startShapeRenderingFilled
public static void startShapeRenderingFilled()Begins shape rendering in filled mode. -
startShapeRenderingOutlined
public static void startShapeRenderingOutlined()Begins shape rendering in outlined (line) mode. -
startShapeRenderingPoints
public static void startShapeRenderingPoints()Begins shape rendering in point mode. -
setLineWidth
public static void setLineWidth(float width) Set the width of the outline when drawing with the shape renderer.- Parameters:
width- Width
-
endShapeRendering
public static void endShapeRendering()Ends the current shape rendering batch. -
clearScreen
public static void clearScreen(int r, int g, int b) Clears the screen to the specified RGB color.- Parameters:
r- red component (0-255)g- green component (0-255)b- blue component (0-255)
-
clearScreen
public static void clearScreen()Clears the screen to black (0, 0, 0). -
clearScreen
Clears the screen using a named color from the color registry.- Parameters:
colorName- the name of the color to clear the screen with (see addColor method)- Throws:
IllegalArgumentException- if the color name is not found
-
clearScreen
public static void clearScreen(com.badlogic.gdx.graphics.Color color) Clears the screen using the specifiedColor.- Parameters:
color- the color to clear the screen with
-
setColor
public static void setColor(com.badlogic.gdx.graphics.Color color) Sets the current drawing color for shapes.- Parameters:
color- theColorto use
-
setColor
public static void setColor(int r, int g, int b) Sets the current drawing color using RGB components (0-255) with full opacity.- Parameters:
r- red component (0-255)g- green component (0-255)b- blue component (0-255)
-
setColor
public static void setColor(int r, int g, int b, int a) Sets the current drawing color using RGBA components (0-255).- Parameters:
r- red component (0-255)g- green component (0-255)b- blue component (0-255)a- alpha component (0-255)
-
setColor
Sets the current drawing color using a registered color name.- Parameters:
colorName- the name of the color to use- Throws:
IllegalArgumentException- if the color name is not found or invalid for masking
-
enableTransparency
public static void enableTransparency()Enable transparency for shape render and sprite batch. -
disableTransparency
public static void disableTransparency()Disable transparency for shape render and sprite batch. -
drawRect
public static void drawRect(float x, float y, float width, float height) Draws a rectangle.- Parameters:
x- the x-coordinate of the bottom-left cornery- the y-coordinate of the bottom-left cornerwidth- the width of the rectangleheight- the height of the rectangle
-
drawRect
Draws a rectangle in a specific color.- Parameters:
x- the x-coordinate of the bottom-left cornery- the y-coordinate of the bottom-left cornerwidth- the width of the rectangleheight- the height of the rectanglecolorName- the name of the color to use
-
drawRect
public static void drawRect(float x, float y, float width, float height, com.badlogic.gdx.graphics.Color color) Draws a rectangle in a specific color.- Parameters:
x- the x-coordinate of the bottom-left cornery- the y-coordinate of the bottom-left cornerwidth- the width of the rectangleheight- the height of the rectanglecolor- the color object
-
drawRectCentered
public static void drawRectCentered(float centerX, float centerY, float width, float height) Draws a rectangle centered on a specified point.- Parameters:
centerX- the x-coordinate of the rectangle's centercenterY- the y-coordinate of the rectangle's centerwidth- the width of the rectangleheight- the height of the rectangle
-
drawRectCentered
public static void drawRectCentered(float centerX, float centerY, float width, float height, String colorName) Draws a rectangle centered on a specified point with a color name.- Parameters:
centerX- the x-coordinate of the rectangle's centercenterY- the y-coordinate of the rectangle's centerwidth- the width of the rectangleheight- the height of the rectanglecolorName- the name of the color to use
-
drawRectCentered
public static void drawRectCentered(float centerX, float centerY, float width, float height, com.badlogic.gdx.graphics.Color color) Draws a rectangle centered on a specified point with a Color object.- Parameters:
centerX- the x-coordinate of the rectangle's centercenterY- the y-coordinate of the rectangle's centerwidth- the width of the rectangleheight- the height of the rectanglecolor- the color object to use
-
drawRoundedRect
public static void drawRoundedRect(float x, float y, float width, float height, float radius) Draws a rounded rectangle using the class's ShapeRenderer.The rectangle consists of a central rectangle, side rectangles, and quarter-circle corners. Note: This only works properly in filled drawing mode. Outline mode will not render correctly.
- Parameters:
x- the x-coordinate of the bottom-left cornery- the y-coordinate of the bottom-left cornerwidth- the width of the rectangleheight- the height of the rectangleradius- the radius of the rounded corners
-
drawRoundedRect
public static void drawRoundedRect(float x, float y, float width, float height, float radius, String colorName) Draws a rounded rectangle with a specified color name.- Parameters:
x- the x-coordinate of the bottom-left cornery- the y-coordinate of the bottom-left cornerwidth- the width of the rectangleheight- the height of the rectangleradius- the radius of the rounded cornerscolorName- the name of the color to use
-
drawRoundedRect
public static void drawRoundedRect(float x, float y, float width, float height, float radius, com.badlogic.gdx.graphics.Color color) Draws a rounded rectangle with a specified Color object.- Parameters:
x- the x-coordinate of the bottom-left cornery- the y-coordinate of the bottom-left cornerwidth- the width of the rectangleheight- the height of the rectangleradius- the radius of the rounded cornerscolor- the Color object to use
-
drawRoundedRectCentered
public static void drawRoundedRectCentered(float centerX, float centerY, float width, float height, float radius) Draws a rounded rectangle centered on a specified point.- Parameters:
centerX- the x-coordinate of the rectangle's centercenterY- the y-coordinate of the rectangle's centerwidth- the width of the rectangleheight- the height of the rectangleradius- the radius of the rounded corners
-
drawRoundedRectCentered
public static void drawRoundedRectCentered(float centerX, float centerY, float width, float height, float radius, String colorName) Draws a rounded rectangle centered on a specified point with a color name.- Parameters:
centerX- the x-coordinate of the rectangle's centercenterY- the y-coordinate of the rectangle's centerwidth- the width of the rectangleheight- the height of the rectangleradius- the radius of the rounded cornerscolorName- the name of the color to use
-
drawRoundedRectCentered
public static void drawRoundedRectCentered(float centerX, float centerY, float width, float height, float radius, com.badlogic.gdx.graphics.Color color) Draws a rounded rectangle centered on a specified point with a Color object.- Parameters:
centerX- the x-coordinate of the rectangle's centercenterY- the y-coordinate of the rectangle's centerwidth- the width of the rectangleheight- the height of the rectangleradius- the radius of the rounded cornerscolor- the Color object to use
-
drawCircle
public static void drawCircle(float x, float y, float radius) Draws a circle.- Parameters:
x- the x-coordinate of the centery- the y-coordinate of the centerradius- the radius of the circle
-
drawCircle
Draws a circle in a specific color.- Parameters:
x- the x-coordinate of the centery- the y-coordinate of the centerradius- the radius of the circlecolorName- the name of the color to use
-
drawCircle
public static void drawCircle(float x, float y, float radius, com.badlogic.gdx.graphics.Color color) Draws a circle in a specific color.- Parameters:
x- the x-coordinate of the centery- the y-coordinate of the centerradius- the radius of the circlecolor- the color object
-
drawCircle
public static void drawCircle(float x, float y, float radius, int segments) Draws a circle with a specified number of segments.- Parameters:
x- the x-coordinate of the centery- the y-coordinate of the centerradius- the radius of the circlesegments- the number of segments used to approximate the circle
-
drawCircle
Draws a circle in a specific color with a specified number of segments.- Parameters:
x- the x-coordinate of the centery- the y-coordinate of the centerradius- the radius of the circlesegments- the number of segments used to approximate the circlecolorName- the name of the color to use
-
drawCircle
public static void drawCircle(float x, float y, float radius, int segments, com.badlogic.gdx.graphics.Color color) Draws a circle in a specific color with a specified number of segments.- Parameters:
x- the x-coordinate of the centery- the y-coordinate of the centerradius- the radius of the circlesegments- the number of segments used to approximate the circlecolor- the color object
-
drawEllipse
public static void drawEllipse(float x, float y, float width, float height) Draws an ellipse.- Parameters:
x- the x-coordinate of the bottom-left cornery- the y-coordinate of the bottom-left cornerwidth- the width of the ellipseheight- the height of the ellipse
-
drawEllipse
Draws an ellipse in a specific color.- Parameters:
x- the x-coordinate of the bottom-left cornery- the y-coordinate of the bottom-left cornerwidth- the width of the ellipseheight- the height of the ellipsecolorName- the name of the color to use
-
drawEllipse
public static void drawEllipse(float x, float y, float width, float height, com.badlogic.gdx.graphics.Color color) Draws an ellipse in a specific color.- Parameters:
x- the x-coordinate of the bottom-left cornery- the y-coordinate of the bottom-left cornerwidth- the width of the ellipseheight- the height of the ellipsecolor- the color object
-
drawEllipseCentered
public static void drawEllipseCentered(float centerX, float centerY, float width, float height) Draws an ellipse centered on a specified point.- Parameters:
centerX- the x-coordinate of the ellipse's centercenterY- the y-coordinate of the ellipse's centerwidth- the width of the ellipseheight- the height of the ellipse
-
drawEllipseCentered
public static void drawEllipseCentered(float centerX, float centerY, float width, float height, String colorName) Draws an ellipse centered on a specified point with a color name.- Parameters:
centerX- the x-coordinate of the ellipse's centercenterY- the y-coordinate of the ellipse's centerwidth- the width of the ellipseheight- the height of the ellipsecolorName- the name of the color to use
-
drawEllipseCentered
public static void drawEllipseCentered(float centerX, float centerY, float width, float height, com.badlogic.gdx.graphics.Color color) Draws an ellipse centered on a specified point with a Color object.- Parameters:
centerX- the x-coordinate of the ellipse's centercenterY- the y-coordinate of the ellipse's centerwidth- the width of the ellipseheight- the height of the ellipsecolor- the color object to use
-
drawLine
public static void drawLine(float x1, float y1, float x2, float y2) Draws a line.- Parameters:
x1- the x-coordinate of the start pointy1- the y-coordinate of the start pointx2- the x-coordinate of the end pointy2- the y-coordinate of the end point
-
drawLine
Draws a line in a specific color.- Parameters:
x1- the x-coordinate of the start pointy1- the y-coordinate of the start pointx2- the x-coordinate of the end pointy2- the y-coordinate of the end pointcolorName- the name of the color to use
-
drawLine
public static void drawLine(float x1, float y1, float x2, float y2, com.badlogic.gdx.graphics.Color color) Draws a line in a specific color.- Parameters:
x1- the x-coordinate of the start pointy1- the y-coordinate of the start pointx2- the x-coordinate of the end pointy2- the y-coordinate of the end pointcolor- the color object
-
drawPolygon
public static void drawPolygon(float[] vertices) Draws a polygon.- Parameters:
vertices- the array of vertices {x1, y1, x2, y2, ...}
-
drawPolygon
Draws a polygon in a specific color.- Parameters:
vertices- the array of vertices {x1, y1, x2, y2, ...}colorName- the name of the color to use
-
drawPolygon
public static void drawPolygon(float[] vertices, com.badlogic.gdx.graphics.Color color) Draws a polygon in a specific color.- Parameters:
vertices- the array of vertices {x1, y1, x2, y2, ...}color- the color object
-
getSpriteBatch
public static com.badlogic.gdx.graphics.g2d.SpriteBatch getSpriteBatch()Returns the sharedSpriteBatchinstance used for rendering sprites.- Returns:
- the global
SpriteBatchinstance
-
startSpriteRendering
public static void startSpriteRendering()Begins sprite rendering.- Throws:
IllegalStateException- if called while a mask is active
-
endSpriteRendering
public static void endSpriteRendering()Ends the current sprite rendering batch. -
addTexture
Loads a texture from a file path and stores it in the global texture registry.- Parameters:
name- the name to associate with the texturefilePath- the internal file path of the texture image
-
addTexture
public static void addTexture(String name, String filePath, com.badlogic.gdx.graphics.Texture.TextureFilter filter) Loads a texture from a file path and stores it in the global texture registry.- Parameters:
name- the name to associate with the texturefilePath- the internal file path of the texture imagefilter- the quality filter for the texture (when scaling)
-
addTexture
public static void addTexture(String name, String filePath, com.badlogic.gdx.graphics.Texture.TextureFilter minFilter, com.badlogic.gdx.graphics.Texture.TextureFilter maxFilter) Loads a texture from a file path and stores it in the global texture registry.- Parameters:
name- the name to associate with the texturefilePath- the internal file path of the texture imageminFilter- the filter used when scaling down the texturemaxFilter- the filter used when scaling up the texture
-
getTexture
Retrieves a texture from the global texture registry by name.- Parameters:
name- the name of the texture- Returns:
- the
Textureassociated with the name - Throws:
IllegalArgumentException- if the texture has not been loaded
-
getTextureWidth
Returns the width in pixels of the texture with the given name.- Parameters:
name- the name or identifier of the texture- Returns:
- the width of the texture in pixels
- Throws:
IllegalArgumentException- if no texture is found for the given name
-
getTextureHeight
Returns the height in pixels of the texture with the given name.- Parameters:
name- the name or identifier of the texture- Returns:
- the height of the texture in pixels
- Throws:
IllegalArgumentException- if no texture is found for the given name
-
hasTexture
Returns if texture is available with the given name- Parameters:
name- Name of the texture- Returns:
- True, if it exists
-
disposeTexture
Remove the texture and unload it from the memory.- Parameters:
name- Name of the texture
-
drawTexture
Draws a texture at the specified position using the current sprite batch.- Parameters:
name- the name of the loaded texturex- the x-coordinate of the bottom-left cornery- the y-coordinate of the bottom-left corner- Throws:
IllegalArgumentException- if the texture has not been loaded
-
drawTexture
Draws a texture at the specified position and size using the current sprite batch.- Parameters:
name- the name of the loaded texturex- the x-coordinate of the bottom-left cornery- the y-coordinate of the bottom-left cornerwidth- the width to draw the textureheight- the height to draw the texture- Throws:
IllegalArgumentException- if the texture has not been loaded
-
drawTexture
public static void drawTexture(String name, float x, float y, float width, float height, float rotationDegrees, boolean flipX, boolean flipY) Draws a texture at the specified position, size, rotation, and flipping using the current sprite batch.The rotation is performed around the center of the drawn texture. Flip parameters allow mirroring horizontally or vertically.
- Parameters:
name- the name of the loaded texturex- the x-coordinate of the bottom-left cornery- the y-coordinate of the bottom-left cornerwidth- the width to draw the textureheight- the height to draw the texturerotationDegrees- the rotation in degrees (clockwise)flipX- whether to flip the texture horizontallyflipY- whether to flip the texture vertically- Throws:
IllegalArgumentException- if the texture has not been loaded
-
drawTextureCentered
Draws a texture centered at the specified position using the current sprite batch.- Parameters:
name- the name of the loaded texturecenterX- the x-coordinate of the centercenterY- the y-coordinate of the center- Throws:
IllegalArgumentException- if the texture has not been loaded
-
drawTextureCentered
public static void drawTextureCentered(String name, float centerX, float centerY, float width, float height) Draws a texture centered at the specified position with size using the current sprite batch.- Parameters:
name- the name of the loaded texturecenterX- the x-coordinate of the centercenterY- the y-coordinate of the centerwidth- the width to draw the textureheight- the height to draw the texture- Throws:
IllegalArgumentException- if the texture has not been loaded
-
drawTextureCentered
public static void drawTextureCentered(String name, float centerX, float centerY, float width, float height, float rotationDegrees, boolean flipX, boolean flipY) Draws a texture centered at the specified position with size, rotation, and flipping using the current sprite batch.Rotation is around the center of the texture.
- Parameters:
name- the name of the loaded texturecenterX- the x-coordinate of the centercenterY- the y-coordinate of the centerwidth- the width to draw the textureheight- the height to draw the texturerotationDegrees- the rotation in degrees (clockwise)flipX- whether to flip the texture horizontallyflipY- whether to flip the texture vertically- Throws:
IllegalArgumentException- if the texture has not been loaded
-
addFont
Loads a TTF or OTF font, optionally scaling it to world height or keeping pixel size.- Parameters:
name- Name to reference the fontfilePath- Path to the TTF/OTF file in assetssize- Font size in pixelsusePixelSize- True to use literal pixel size (good for HUD), false to scale to world height
-
addFont
Overload: Adds a font that scales to world height by default.- Parameters:
name- Name to reference the fontfilePath- Path to the TTF/OTF filesize- Font size in pixels
-
addFont
Registers an already createdBitmapFontunder a given name.- Parameters:
name- Name to reference the fontfont- Pre-created BitmapFont
-
addStyledFont
public static void addStyledFont(String name, String filePath, int size, com.badlogic.gdx.graphics.Color color, float borderWidth, com.badlogic.gdx.graphics.Color borderColor, int shadowOffsetX, int shadowOffsetY, com.badlogic.gdx.graphics.Color shadowColor, boolean usePixelSize) Loads a styled TTF font with optional border and shadow, with world-scaling or pixel-perfect option.- Parameters:
name- Name to reference the fontfilePath- Path to the TTF/OTF filesize- Font size in pixelscolor- Base colorborderWidth- Width of border (0 = no border)borderColor- Color of border (ignored if borderWidth = 0)shadowOffsetX- Shadow X offsetshadowOffsetY- Shadow Y offsetshadowColor- Shadow colorusePixelSize- True to use pixel size (HUD), false to scale to world height
-
addStyledFont
public static void addStyledFont(String name, String filePath, int size, String colorName, float borderWidth, String borderColorName, int shadowOffsetX, int shadowOffsetY, String shadowColorName, boolean usePixelSize) Styled font with named colors (throws if color names not found).- Parameters:
name- Name to reference the fontfilePath- TTF/OTF file pathsize- Font sizecolorName- Base color nameborderWidth- Border widthborderColorName- Border color nameshadowOffsetX- Shadow X offsetshadowOffsetY- Shadow Y offsetshadowColorName- Shadow color nameusePixelSize- True = pixel size, false = world-scaled
-
getFont
Retrieves a loaded font by its name.- Parameters:
name- Name of the loaded font.- Returns:
- The BitmapFont associated with the given name.
- Throws:
IllegalArgumentException- if the font is not found.
-
hasFont
Returns if font is available with the given name- Parameters:
name- Name of the font- Returns:
- True, if it exists
-
disposeFont
Remove the font and unload it from the memory.- Parameters:
name- Name of the font.
-
drawText
public static void drawText(String fontName, String text, float x, float y, com.badlogic.gdx.graphics.Color color) Draws text left-bottom aligned at the specified position with a given color.- Parameters:
fontName- Name of the loaded font.text- Text to draw.x- X-coordinate of the bottom-left corner of the text.y- Y-coordinate of the bottom-left corner of the text.color- Color to render the text.
-
drawText
Draws text left-bottom aligned at the specified position with a given color.- Parameters:
fontName- Name of the loaded font.text- Text to draw.x- X-coordinate of the bottom-left corner of the text.y- Y-coordinate of the bottom-left corner of the text.color- Color to render the text.
-
drawTextCentered
public static void drawTextCentered(String fontName, String text, float centerX, float centerY, com.badlogic.gdx.graphics.Color color) Draws text centered on a specified point with a given color.- Parameters:
fontName- Name of the loaded font.text- Text to draw.centerX- X-coordinate of the center of the text.centerY- Y-coordinate of the center of the text.color- Color to render the text.
-
drawTextCentered
public static void drawTextCentered(String fontName, String text, float centerX, float centerY, String color) Draws text centered on a specified point with a given color.- Parameters:
fontName- Name of the loaded font.text- Text to draw.centerX- X-coordinate of the center of the text.centerY- Y-coordinate of the center of the text.color- Color to render the text.
-
drawTextHorizontallyCentered
public static void drawTextHorizontallyCentered(String fontName, String text, float centerX, float y, com.badlogic.gdx.graphics.Color color) Draws text horizontally centered at a given X-coordinate with a given Y-coordinate and color.- Parameters:
fontName- Name of the loaded font.text- Text to draw.centerX- X-coordinate of the horizontal center of the text.y- Y-coordinate for the text baseline.color- Color to render the text.
-
drawTextHorizontallyCentered
public static void drawTextHorizontallyCentered(String fontName, String text, float centerX, float y, String color) Overload with color as string. -
drawTextVerticallyCentered
public static void drawTextVerticallyCentered(String fontName, String text, float x, float centerY, com.badlogic.gdx.graphics.Color color) Draws text vertically centered at a given Y-coordinate with a given X-coordinate and color.- Parameters:
fontName- Name of the loaded font.text- Text to draw.x- X-coordinate for the left of the text.centerY- Y-coordinate of the vertical center of the text.color- Color to render the text.
-
drawTextVerticallyCentered
public static void drawTextVerticallyCentered(String fontName, String text, float x, float centerY, String color) Overload with color as string. -
getTextWidth
Returns the width of a given text in pixels when rendered with the specified font.- Parameters:
fontName- Name of the loaded font.text- Text to measure.- Returns:
- Width of the text in pixels.
-
getTextHeight
Returns the height of a given text in pixels when rendered with the specified font.- Parameters:
fontName- Name of the loaded font.text- Text to measure.- Returns:
- Height of the text in pixels.
-
clamp
public static float clamp(float value, float min, float max) Clamps a value to be within the specified minimum and maximum range.- Parameters:
value- the value to clampmin- the minimum allowable valuemax- the maximum allowable value- Returns:
- the clamped value; if
valueis less thanmin, returnsmin, ifvalueis greater thanmax, returnsmax, otherwise returnsvalueitself
-
random
public static float random(float min, float max) Returns a random float value within the specified range. The minimim is inclusive, the maximum is exclusive.- Parameters:
min- the lower boundmax- the upper bound- Returns:
- a random float between
minandmax
-
randomInt
public static int randomInt(int min, int max) Returns a random int value within the specified range. The minimim is inclusive, the maximum is exclusive.- Parameters:
min- the lower boundmax- the upper bound- Returns:
- a random int between
minandmax
-
random
public static <T> T random(T[] array) Returns a random element from an array.- Type Parameters:
T- type of elements- Parameters:
array- the array to pick from- Returns:
- a random element from the array
- Throws:
IllegalArgumentException- if the array is null or empty
-
random
Returns a random element from a List of any type.- Type Parameters:
T- the type of elements- Parameters:
list- the list to pick from- Returns:
- a random element from the list
- Throws:
IllegalArgumentException- if the list is null or empty
-
rectOverlap
public static boolean rectOverlap(float x1, float y1, float w1, float h1, float x2, float y2, float w2, float h2) Checks if two axis-aligned rectangles overlap.- Parameters:
x1- X of first rectangley1- Y of first rectanglew1- Width of first rectangleh1- Height of first rectanglex2- X of second rectangley2- Y of second rectanglew2- Width of second rectangleh2- Height of second rectangle- Returns:
- true if the rectangles intersect
-
rectOverlap
public static boolean rectOverlap(com.badlogic.gdx.math.Rectangle r1, com.badlogic.gdx.math.Rectangle r2) -
circleOverlap
public static boolean circleOverlap(float x1, float y1, float r1, float x2, float y2, float r2) Checks if two circles overlap.- Parameters:
x1- X center of first circley1- Y center of first circler1- Radius of first circlex2- X center of second circley2- Y center of second circler2- Radius of second circle- Returns:
- true if the circles intersect
-
circleOverlap
public static boolean circleOverlap(com.badlogic.gdx.math.Circle c1, com.badlogic.gdx.math.Circle c2) -
rectCircleOverlap
public static boolean rectCircleOverlap(float rectX, float rectY, float rectW, float rectH, float circleX, float circleY, float radius) Checks if an axis-aligned rectangle and a circle overlap.- Parameters:
rectX- X of rectanglerectY- Y of rectanglerectW- Width of rectanglerectH- Height of rectanglecircleX- X center of circlecircleY- Y center of circleradius- Radius of circle- Returns:
- true if the rectangle and circle intersect
-
rectCircleOverlap
public static boolean rectCircleOverlap(com.badlogic.gdx.math.Rectangle rect, com.badlogic.gdx.math.Circle circle) -
pointInRect
public static boolean pointInRect(float px, float py, float rx, float ry, float rw, float rh) Checks if a point is inside a rectangle.- Parameters:
px- X coordinate of the pointpy- Y coordinate of the pointrx- X of rectanglery- Y of rectanglerw- Width of rectanglerh- Height of rectangle- Returns:
- true if the point is inside the rectangle
-
pointInRect
public static boolean pointInRect(com.badlogic.gdx.math.Vector2 point, com.badlogic.gdx.math.Rectangle rect) -
pointInCircle
public static boolean pointInCircle(float px, float py, float cx, float cy, float radius) Checks if a point is inside a circle.- Parameters:
px- X coordinate of the pointpy- Y coordinate of the pointcx- X center of circlecy- Y center of circleradius- Radius of the circle- Returns:
- true if the point is inside the circle
-
pointInCircle
public static boolean pointInCircle(com.badlogic.gdx.math.Vector2 point, com.badlogic.gdx.math.Circle circle) -
rectContainsRect
public static boolean rectContainsRect(float x1, float y1, float w1, float h1, float x2, float y2, float w2, float h2) Checks if one rectangle is completely contained within another rectangle.- Parameters:
x1- X of outer rectangley1- Y of outer rectanglew1- Width of outer rectangleh1- Height of outer rectanglex2- X of inner rectangley2- Y of inner rectanglew2- Width of inner rectangleh2- Height of inner rectangle- Returns:
- true if the inner rectangle is fully inside the outer rectangle
-
rectContainsRect
public static boolean rectContainsRect(com.badlogic.gdx.math.Rectangle outer, com.badlogic.gdx.math.Rectangle inner) -
distance
public static float distance(float x1, float y1, float x2, float y2) Calculates the distance between two points.- Parameters:
x1- X of first pointy1- Y of first pointx2- X of second pointy2- Y of second point- Returns:
- distance between the points
-
angleBetween
public static float angleBetween(float x1, float y1, float x2, float y2) Calculates the angle in degrees from the first point to the second point. 0 degrees points to the right (positive X axis), angles increase counter-clockwise.- Parameters:
x1- X of first pointy1- Y of first pointx2- X of second pointy2- Y of second point- Returns:
- angle in degrees from the first point to the second point
-
moveInDirection
public static float[] moveInDirection(float x, float y, float distance, float directionDegrees) Computes new coordinates by moving from a starting point in a specified direction and distance.The direction is in degrees, where 0° points to the right (positive X-axis) and increases counterclockwise: 90° is up, 180° is left, 270° is down.
- Parameters:
x- the starting x-coordinatey- the starting y-coordinatedistance- the distance to move (can also be thought of as speed)directionDegrees- the movement direction in degrees- Returns:
- a float array of length 2, where index 0 is the new x-coordinate and index 1 is the new y-coordinate
-
addItemToStore
Add item to the application store, so that it can be used in multiple screens.- Parameters:
name- Key in the storeanyType- Object to store
-
hasItemInStore
Check if an item exists with the given name- Parameters:
name- Name of the item- Returns:
- True, in case the item exists.
-
getItemFromStore
Get an item from the application store by name.- Parameters:
name- Name of the item in the store- Returns:
- Object, if available. Otherwise, exception.
-
removeItemFromStore
Remove an item from the store by name.- Parameters:
name- Name of the item- Returns:
- true if the item existed and was removed, false otherwise
-
saveToBinary
Saves any object to a binary file.- Parameters:
object- the object to serializefileName- the file name (e.g., "savegame.bin")
-
loadFromBinary
Loads any object from a binary file.- Parameters:
fileName- the file name- Returns:
- the deserialized object, or null if file doesn't exist
-
fileExists
Checks if the save file exists.- Parameters:
fileName- filename- Returns:
- true, if the file exists
-
saveToJson
Serialize any object to JSON and save to a file.- Parameters:
object- the object to serializefileName- the file name (e.g., "savegame.json")
-
loadFromJson
Load an object from a JSON file.- Type Parameters:
T- the type parameter- Parameters:
fileName- the file nametype- the class type of the object to load- Returns:
- the deserialized object
- Throws:
IllegalArgumentException- if the file doesn't exist
-
addInterpolator
public static void addInterpolator(String name, float start, float end, float duration, com.badlogic.gdx.math.Interpolation strategy) Creates a new interpolator with the given name. If an interpolator with the same name exists, it will be replaced.- Parameters:
name- the unique name of the interpolatorstart- the starting valueend- the ending valueduration- the duration of the interpolation in secondsstrategy- the interpolation strategy (e.g.,Interpolation.pow2Out,Interpolation.bounce)
-
addInterpolator
public static void addInterpolator(String name, float start, float end, float duration, String strategy) Creates a new interpolator with the given name. If an interpolator with the same name exists, it will be replaced.- Parameters:
name- the unique name of the interpolatorstart- the starting valueend- the ending valueduration- the duration of the interpolation in secondsstrategy- the interpolation strategy (e.g., "bounce", "elastic", "pow1")
-
getInterpolationStrategies
Get a list of all the possible interpolation strategies available- Returns:
- String[] with all possible interpolation strategies.
-
disposeInterpolator
Removes an interpolator from the internal registry. After calling this, the interpolator with the given name will no longer exist.- Parameters:
name- the name of the interpolator to remove (case-insensitive)
-
hasInterpolator
Checks whether an interpolator with the given name exists.- Parameters:
name- the name of the interpolator to check (case-insensitive)- Returns:
trueif the interpolator exists,falseotherwise
-
getInterpolator
Retrieves an existing interpolator by name. Use this if you need to access the interpolator object directly.- Parameters:
name- the name of the interpolator to retrieve (case-insensitive)- Returns:
- the
Interpolatorinstance, ornullif it does not exist
-
updateInterpolator
Updates the interpolator with the given name and returns the current value.This method should be called every frame (e.g., inside the render loop).
- Parameters:
name- the name of the interpolator- Returns:
- the current interpolated value
- Throws:
IllegalArgumentException- if no interpolator exists with the given name
-
isInterpolatorFinished
Checks whether the interpolator has finished its animation.- Parameters:
name- the name of the interpolator- Returns:
- true if the interpolation has completed, false otherwise
- Throws:
IllegalArgumentException- if no interpolator exists with the given name
-
resetInterpolator
Resets the interpolator with the given name to start its animation from the beginning. If the interpolator does not exist, this method does nothing.- Parameters:
name- the name of the interpolator
-
resetInterpolator
Resets the interpolator with the given name to start its animation from the beginning. If the interpolator does not exist, this method does nothing.- Parameters:
name- the name of the interpolatorreverse- should the animation be reversed?
-
addSpriteSheet
Loads a spritesheet from a file, slices it into frames, and stores the frames. The underlying Texture is not added to the global texture map.- Parameters:
name- the name to identify the spritesheetfilePath- the internal file path of the textureframeWidth- the width of a single frameframeHeight- the height of a single frame
-
getSpritesheetFrame
public static com.badlogic.gdx.graphics.g2d.TextureRegion getSpritesheetFrame(String name, int row, int col) Retrieve a specific frame from a spritesheet.- Parameters:
name- the spritesheet namerow- the row index (0-based)col- the column index (0-based)- Returns:
- the TextureRegion for the requested frame
- Throws:
IllegalArgumentException- if the spritesheet does not existIndexOutOfBoundsException- if row/col are invalid
-
drawSpritesheetFrame
Draw a specific frame from a spritesheet at the given position.- Parameters:
name- the spritesheet namerow- the row index (0-based)col- the column index (0-based)x- the x-coordinate of the bottom-left cornery- the y-coordinate of the bottom-left corner
-
drawSpritesheetFrame
public static void drawSpritesheetFrame(String name, int row, int col, float x, float y, float width, float height) Draw a specific frame with scaling.- Parameters:
name- the spritesheet namerow- the row index (0-based)col- the column index (0-based)x- the x-coordinatey- the y-coordinatewidth- the width to drawheight- the height to draw
-
drawSpritesheetFrame
public static void drawSpritesheetFrame(String name, int row, int col, float x, float y, float width, float height, float rotationDegrees, boolean flipX, boolean flipY) Draw a specific frame with scaling, rotation, and flipping.- Parameters:
name- the spritesheet namerow- the row index (0-based)col- the column index (0-based)x- the x-coordinatey- the y-coordinatewidth- the width to drawheight- the height to drawrotationDegrees- rotation in degrees (clockwise)flipX- whether to flip horizontallyflipY- whether to flip vertically
-
drawSpritesheetFrameCentered
public static void drawSpritesheetFrameCentered(String name, int row, int col, float centerX, float centerY) Draw a frame centered at a given position.- Parameters:
name- the spritesheet namerow- the row index (0-based)col- the column index (0-based)centerX- the x-coordinate of the centercenterY- the y-coordinate of the center
-
drawSpritesheetFrameCentered
public static void drawSpritesheetFrameCentered(String name, int row, int col, float centerX, float centerY, float width, float height) Draw a frame centered with scaling.- Parameters:
name- the spritesheet namerow- the row index (0-based)col- the column index (0-based)centerX- the x-coordinate of the centercenterY- the y-coordinate of the centerwidth- the width to drawheight- the height to draw
-
drawSpritesheetFrameCentered
public static void drawSpritesheetFrameCentered(String name, int row, int col, float centerX, float centerY, float width, float height, float rotationDegrees, boolean flipX, boolean flipY) Draw a frame centered with scaling, rotation, and flipping.- Parameters:
name- the spritesheet namerow- the row index (0-based)col- the column index (0-based)centerX- the x-coordinate of the centercenterY- the y-coordinate of the centerwidth- the width to drawheight- the height to drawrotationDegrees- rotation in degrees (clockwise)flipX- whether to flip horizontallyflipY- whether to flip vertically
-
getSpritesheetNumberOfRows
Returns the number of rows in the specified spritesheet.- Parameters:
name- the name of the spritesheet- Returns:
- the number of rows
- Throws:
IllegalArgumentException- if the spritesheet does not exist
-
getSpritesheetNumberOfCols
Returns the number of columns in the specified spritesheet.Assumes all rows have the same number of columns.
- Parameters:
name- the name of the spritesheet- Returns:
- the number of columns
- Throws:
IllegalArgumentException- if the spritesheet does not exist
-
hasSpritesheet
Returns if a spritesheet is available with the given name.- Parameters:
name- the name of the spritesheet- Returns:
- true if it exists, false otherwise
-
disposeSpritesheet
Removes the spritesheet and disposes its underlying Texture.- Parameters:
name- the name of the spritesheet
-
addTextureAtlas
Loads a texture atlas and stores it in the internal atlas map.- Parameters:
name- the name to identify the atlasfilePath- the path to the .atlas file
-
hasAtlas
Returns if an atlas is available with the given name- Parameters:
name- the name of the atlas- Returns:
- true if it exists, false otherwise
-
disposeAtlas
Removes the atlas and disposes it from memory.- Parameters:
name- the name of the atlas
-
getAtlasRegion
public static com.badlogic.gdx.graphics.g2d.TextureRegion getAtlasRegion(String atlasName, String regionName) Retrieves aTextureRegionfrom a loaded texture atlas.This method automatically supports both single-region and indexed multi-region atlases. If the region name ends with an underscore followed by a number (e.g. "walk_1"), the method will interpret it as an indexed region and fetch the correct frame from the corresponding atlas sequence.
For example:
getAtlasRegion("characters", "walk_0"); // retrieves the first frame getAtlasRegion("characters", "walk_1"); // retrieves the second frame getAtlasRegion("characters", "idle"); // retrieves a single non-indexed region- Parameters:
atlasName- the name of the atlasregionName- the name of the region inside the atlas (optionally ending with _N)- Returns:
- the
TextureRegionfor the requested region - Throws:
IllegalArgumentException- if the atlas or region does not exist
-
getAtlas
Get the texture atlas object.- Parameters:
name- Name of the texture atlas- Returns:
- Texture atlas object
-
drawAtlasRegion
Draws a region from an atlas at the specified position.- Parameters:
atlasName- the name of the atlasregionName- the name of the regionx- the x-coordinate of the bottom-left cornery- the y-coordinate of the bottom-left corner
-
drawAtlasRegion
public static void drawAtlasRegion(String atlasName, String regionName, float x, float y, float width, float height) Draws a region from an atlas at the specified position with scaling.- Parameters:
atlasName- the name of the atlasregionName- the name of the regionx- the x-coordinatey- the y-coordinatewidth- the width to drawheight- the height to draw
-
drawAtlasRegion
public static void drawAtlasRegion(String atlasName, String regionName, float x, float y, float width, float height, float rotationDegrees, boolean flipX, boolean flipY) Draws a region from an atlas at the specified position with scaling, rotation, and flipping.- Parameters:
atlasName- the name of the atlasregionName- the name of the regionx- the x-coordinatey- the y-coordinatewidth- the width to drawheight- the height to drawrotationDegrees- rotation in degrees (clockwise)flipX- whether to flip horizontallyflipY- whether to flip vertically
-
drawAtlasRegionCentered
public static void drawAtlasRegionCentered(String atlasName, String regionName, float centerX, float centerY) Draws a region from an atlas centered at a given position.- Parameters:
atlasName- the name of the atlasregionName- the name of the regioncenterX- the x-coordinate of the centercenterY- the y-coordinate of the center
-
drawAtlasRegionCentered
public static void drawAtlasRegionCentered(String atlasName, String regionName, float centerX, float centerY, float width, float height) Draws a region from an atlas centered with scaling.- Parameters:
atlasName- the name of the atlasregionName- the name of the regioncenterX- the x-coordinate of the centercenterY- the y-coordinate of the centerwidth- the width to drawheight- the height to draw
-
drawAtlasRegionCentered
public static void drawAtlasRegionCentered(String atlasName, String regionName, float centerX, float centerY, float width, float height, float rotationDegrees, boolean flipX, boolean flipY) Draws a region from an atlas centered with scaling, rotation, and flipping.- Parameters:
atlasName- the name of the atlasregionName- the name of the regioncenterX- the x-coordinate of the centercenterY- the y-coordinate of the centerwidth- the width to drawheight- the height to drawrotationDegrees- rotation in degrees (clockwise)flipX- whether to flip horizontallyflipY- whether to flip vertically
-
addEmptyAnimation
Creates an empty animation with a given frame duration and loop flag. Frames can be added manually later using addAnimationFrame or addAnimationFrameFromAtlas.- Parameters:
name- the unique name of the animationframeDuration- the duration of each frame in secondsloop- whether the animation should loop
-
addAnimationFromSpritesheet
public static void addAnimationFromSpritesheet(String name, String spritesheet, float frameDuration, boolean loop) Adds a new animation using all frames from the specified spritesheet. Frames are taken row by row, left to right. Replaces any existing animation with the same name.- Parameters:
name- the unique animation namespritesheet- the name of the spritesheetframeDuration- seconds per frameloop- whether the animation should loop- Throws:
IllegalArgumentException- if the spritesheet does not exist
-
addAnimation
public static void addAnimation(String name, com.badlogic.gdx.graphics.g2d.TextureRegion[] frames, float frameDuration, boolean loop) Adds a new animation using manually specified frames. Replaces any existing animation with the same name.- Parameters:
name- the unique animation nameframes- the array of frames to useframeDuration- seconds per frameloop- whether the animation should loop
-
addAnimationFrameFromSpritesheet
public static void addAnimationFrameFromSpritesheet(String animationName, String spritesheet, int row, int col) Adds a single frame from a spritesheet (by row and column) to an existing animation.The animation **must already exist**. Use
addEmptyAnimation(String, float, boolean)or one of the other add-animation methods to create it first.- Parameters:
animationName- the name of the animation (must already exist)spritesheet- the name of the spritesheetrow- the row index (0-based)col- the column index (0-based)- Throws:
IllegalArgumentException- if the spritesheet or animation does not existIndexOutOfBoundsException- if row/col are out of bounds
-
addAnimationFromAtlas
public static void addAnimationFromAtlas(String name, String atlasName, String prefix, float frameDuration, boolean loop) Creates a new animation using all regions in a given atlas that match a prefix. Regions are automatically sorted alphabetically.- Parameters:
name- the name of the animationatlasName- the name of the loaded atlasprefix- the prefix of the region names to include (e.g., "run_")frameDuration- duration of each frame in secondsloop- whether the animation should loop
-
addAnimationFrameFromAtlas
public static void addAnimationFrameFromAtlas(String animationName, String atlasName, String regionName) Adds a single region from an atlas to an existing animation.- Parameters:
animationName- the name of the animationatlasName- the name of the atlasregionName- the specific region name to add
-
hasAnimation
Checks if an animation exists.- Parameters:
name- the animation name- Returns:
- true if it exists
-
disposeAnimation
Removes an animation.- Parameters:
name- the animation name
-
getAnimation
Retrieves an animation by name.- Parameters:
name- the animation name- Returns:
- the SpriteAnimation instance, or null if it does not exist
-
updateAnimation
Updates the animation by the frame's delta time.Students do not need to handle
TextureRegiondirectly; drawing methods will automatically use the current frame.- Parameters:
name- the name of the animation- Throws:
IllegalArgumentException- if no animation exists with the given name
-
drawAnimation
Draws the current frame of the animation at the specified bottom-left position.- Parameters:
name- the name of the animationx- the x-coordinate of the bottom-left cornery- the y-coordinate of the bottom-left corner- Throws:
IllegalArgumentException- if no animation exists with the given name
-
drawAnimation
Draws the current frame of the animation at the specified position and size.- Parameters:
name- the name of the animationx- the x-coordinate of the bottom-left cornery- the y-coordinate of the bottom-left cornerwidth- the width to drawheight- the height to draw- Throws:
IllegalArgumentException- if no animation exists with the given name
-
drawAnimation
public static void drawAnimation(String name, float x, float y, float width, float height, float rotationDegrees, boolean flipX, boolean flipY) Draws the current frame of the animation at the specified position, size, rotation, and flipping.- Parameters:
name- the name of the animationx- the x-coordinate of the bottom-left cornery- the y-coordinate of the bottom-left cornerwidth- the width to drawheight- the height to drawrotationDegrees- rotation in degrees (clockwise)flipX- whether to flip the frame horizontallyflipY- whether to flip the frame vertically- Throws:
IllegalArgumentException- if no animation exists with the given name
-
drawAnimationCentered
Draws the current frame of the animation centered at the specified position.- Parameters:
name- the name of the animationcenterX- the x-coordinate of the centercenterY- the y-coordinate of the center- Throws:
IllegalArgumentException- if no animation exists with the given name
-
drawAnimationCentered
public static void drawAnimationCentered(String name, float centerX, float centerY, float width, float height) Draws the current frame of the animation centered at the specified position with the given size.- Parameters:
name- the name of the animationcenterX- the x-coordinate of the centercenterY- the y-coordinate of the centerwidth- the width to drawheight- the height to draw- Throws:
IllegalArgumentException- if no animation exists with the given name
-
drawAnimationCentered
public static void drawAnimationCentered(String name, float centerX, float centerY, float width, float height, float rotationDegrees, boolean flipX, boolean flipY) Draws the current frame of the animation centered at the specified position with size, rotation, and flipping.- Parameters:
name- the name of the animationcenterX- the x-coordinate of the centercenterY- the y-coordinate of the centerwidth- the width to drawheight- the height to drawrotationDegrees- rotation in degrees (clockwise)flipX- whether to flip the frame horizontallyflipY- whether to flip the frame vertically- Throws:
IllegalArgumentException- if no animation exists with the given name
-
isAnimationFinished
Checks if the animation has finished.- Parameters:
name- the animation name- Returns:
- true if finished, false otherwise
- Throws:
IllegalArgumentException- if no animation exists with the given name
-
resetAnimation
Resets an animation to start from the beginning.- Parameters:
name- the animation name
-
resetAnimation
Resets an animation to start from the beginning, optionally reversing it.- Parameters:
name- the animation namereverse- whether to reverse the animation
-
jumpAnimationToFrame
Jumps the named animation to a specific frame.- Parameters:
name- the name of the animationframeIndex- the 0-based index of the frame- Throws:
IllegalArgumentException- if no animation exists with the given nameIndexOutOfBoundsException- if the frame index is invalid
-
getAnimationCurrentFrameIndex
Returns the index of the current frame of the named animation.- Parameters:
name- the name of the animation- Returns:
- the 0-based index of the current frame
- Throws:
IllegalArgumentException- if no animation exists with the given name
-
getAnimationFrameCount
Returns the total number of frames in the named animation.- Parameters:
name- the name of the animation- Returns:
- the total number of frames
- Throws:
IllegalArgumentException- if no animation exists with the given name
-
hideCursor
public static void hideCursor()Hides the system mouse cursor.The cursor will be invisible, but you can still get the mouse coordinates.
-
showCursor
public static void showCursor()Shows the default system mouse cursor. -
setCustomCursor
Sets a custom cursor image from a file.- Parameters:
filePath- the path to the cursor image (PNG)hotspotX- the x-coordinate of the active point (tip)hotspotY- the y-coordinate of the active point (tip)
-
setSystemCursor
public static void setSystemCursor(com.badlogic.gdx.graphics.Cursor.SystemCursor systemCursor) Sets the system cursor to one of the default cursors.- Parameters:
systemCursor- the system cursor to use (e.g., Arrow, Hand, Crosshair, VerticalResize)
-
startMask
public static void startMask()Starts a new mask definition. All subsequent shapes or textures will define the mask area.- Throws:
IllegalStateException- if sprite or shape rendering is currently active
-
endMask
public static void endMask()Ends the mask definition and applies it to subsequent drawing. By default, the mask shows what was drawn in the mask layer. -
invertMask
public static void invertMask()Inverts the mask effect. Subsequent drawing will render outside the mask instead of inside it. -
clearMask
public static void clearMask()Clears the mask completely. Subsequent drawing will not be affected by any mask. -
addParticleEffect
Load a particle effect and create a pool for it.- Parameters:
name- unique name of the effectfilePath- path to the .p file (particle image must be in the same folder)
-
spawnParticleEffect
Spawn a particle effect at a position.- Parameters:
name- the particle effect namex- x-coordinate in the worldy- y-coordinate in the world- Returns:
- unique ID of this spawned effect
-
stopParticleEffect
public static void stopParticleEffect(long id) Stop a specific active particle effect.- Parameters:
id- the unique ID returned from spawnParticleEffect
-
updateParticleEffects
public static void updateParticleEffects()Update all active particle effects. Uses delta from Gdx.graphics.getDeltaTime(). -
renderParticleEffects
public static void renderParticleEffects()Render all active particle effects using GameApp.spriteBatch. -
renderParticleEffect
Draw one specific particle effect instance. In most cases you want to use the method `renderParticleEffects()`, to render all effects at the same time!- Parameters:
id- Id of the particle effect instance
-
isParticleEffectFinished
Checks if the particle effect instance has finished- Parameters:
id- Id of the particle effect instance- Returns:
- True if it has finished
-
stopAllActiveParticleEffects
public static void stopAllActiveParticleEffects()Clears all active effects and returns them to their pools. -
getParticleEffectPool
Only for advanced users: get the particle pool object from the app directly. With this object you can trigger all particle effects manually.- Parameters:
name- Name of the particle effect- Returns:
- ParticlePool object
-
getActiveParticleEffects
public static long[] getActiveParticleEffects()Get a list with all active particle id's- Returns:
- List with active particle id's
-
hasParticleEffect
Checks whether a particle effect pool exists for the given name.- Parameters:
name- the particle effect name- Returns:
- true if the pool exists, false otherwise
-
disposeParticleEffect
Remove the particle effect by name. This will not stop the active particle effect!- Parameters:
name- the name of the particle effect to dispose
-
addTimer
Add a timer.- Parameters:
name- unique timer nameduration- duration in secondsloops- -1 = infinite, 1 = single-shot, >1 = limited loops
-
addTimer
Add a timer with simple looping boolean.- Parameters:
name- timer nameduration- duration in secondslooping- true = infinite, false = single-shot
-
hasTimer
Returns true if a timer exists. -
getTimer
Retrieve timer object. -
disposeTimer
Dispose of timer. -
resetTimer
Reset timer to initial state. -
pauseTimer
Pause timer. -
resumeTimer
Resume timer. -
setTimerDuration
Change timer duration. -
getTimerRemaining
Get remaining time until next trigger. -
updateTimers
public static void updateTimers()Update all timers using Gdx deltaTime. Call once per frame. -
updateTimer
Update single timer using Gdx deltaTime. -
timerWentOff
Query if a timer went off in the last update call. This does NOT update the timer. -
isTimerFinished
Checks whether a timer has finished all its loops.For infinite timers (-1 loops), this always returns false.
- Parameters:
name- the timer name- Returns:
- true if finished, false otherwise
- Throws:
IllegalArgumentException- if no timer exists with the given name
-
log
Prints a simple message to the console.- Parameters:
message- the message to print
-
log
Prints a variable with its name for easier debugging.- Parameters:
name- the name of the variablevalue- the value of the variable
-
warn
Prints a warning message in yellow.- Parameters:
message- the warning message
-
error
Prints an error message in red.- Parameters:
message- the error message
-
debug
Prints multiple values in a single line. Useful for quick debugging of multiple variables.- Parameters:
values- the values to print (can include labels)
-
assertCondition
Checks a condition and prints a message if it fails. Useful for teaching simple assertions.- Parameters:
condition- the condition to testmessage- the message to print if condition is false
-
addSkin
Adds a skin to the internal skin registry by loading it from a JSON file. The JSON file must reference the associated texture atlas correctly.- Parameters:
key- unique key to reference the skin laterjsonPath- path to the skin JSON file in the assets folder (e.g., "skins/ui.json")- Throws:
GdxRuntimeException- if the skin or atlas cannot be loaded
-
hasSkin
Checks whether a skin exists in the registry.- Parameters:
key- skin key- Returns:
- true if the skin exists
-
getSkin
Retrieves a skin from the registry by its key.- Parameters:
key- skin key- Returns:
- Skin object or null if not found
-
disposeSkin
Disposes of a skin in the registry.- Parameters:
key- skin key
-
disposeUIElements
public static void disposeUIElements()Removes all UI elements from the current HUD stage. -
addCustomUIComponent
public static void addCustomUIComponent(String name, com.badlogic.gdx.scenes.scene2d.Actor uiComponent) Adds a custom LibGDXActorto the currently active HUD.This method can be used to add any UI element that is not yet supported by the convenience methods, such as images, custom widgets, or third-party actors. When the actor triggers any events, you should handle them inside the actor itself or by adding listeners.
- Parameters:
name- unique key for the UI elementuiComponent- theActorto add to the HUD stage- Throws:
IllegalStateException- if no active HUD is available or HUD is disabledRuntimeException- if an element with the same name already exists
-
getUIElement
Retrieves the raw LibGDXActorfor a given UI element key.This works for any UI element added via GameApp's addButton, addSlider, addCheckBox, addTextField, addSelectBox, addProgressBar, or addCustomUIComponent methods.
- Parameters:
name- the key of the UI element- Returns:
- the
Actorassociated with the key - Throws:
IllegalArgumentException- if no UI element with the given name exists
-
hasUIElement
Checks whether a UI element with the given key exists in the currently active HUD.- Parameters:
name- the key of the UI element- Returns:
- true if the element exists, false otherwise
-
addButton
public static void addButton(String name, String skinName, float x, float y, float width, float height, String text) Adds aTextButtonto the currently active HUD.When the button is clicked,
HUD.onUIInteraction(String, Object)will be called with the button's key and anullvalue.- Parameters:
name- unique key for the buttonskinName- name of the skin to usex- X position in HUD coordinatesy- Y position in HUD coordinateswidth- button widthheight- button heighttext- text displayed on the button- Throws:
RuntimeException- if the specified skin cannot be foundIllegalStateException- if no active HUD is available or HUD is disabled
-
addCheckBox
public static void addCheckBox(String name, String skinName, float x, float y, String text, boolean checked) Adds aCheckBoxto the currently active HUD.The checkbox can be used for boolean user input. When its state changes,
HUD.onUIInteraction(String, Object)is called with the checkbox's key and aBooleanindicating its new state.- Parameters:
name- unique key for the checkboxskinName- name of the skin to usex- X position in HUD coordinatesy- Y position in HUD coordinatestext- label text displayed next to the checkboxchecked- whether the checkbox is initially checked- Throws:
RuntimeException- if the specified skin cannot be foundIllegalStateException- if no active HUD is available or HUD is disabled
-
addSlider
public static void addSlider(String name, String skinName, float x, float y, float width, float height, float min, float max, float step, boolean vertical) Adds aSliderto the currently active HUD.Sliders allow users to select a value in a numeric range by dragging. When the slider's value changes,
HUD.onUIInteraction(String, Object)is called with the slider’s key and current float value.- Parameters:
name- unique key for the sliderskinName- name of the skin to usex- X position in HUD coordinatesy- Y position in HUD coordinateswidth- slider widthheight- slider heightmin- minimum slider valuemax- maximum slider valuestep- increment step sizevertical- true for vertical, false for horizontal- Throws:
RuntimeException- if the specified skin cannot be foundIllegalStateException- if no active HUD is available or HUD is disabled
-
addTextField
public static void addTextField(String name, String skinName, float x, float y, float width, float height, String messageText) Adds aTextField(input box) to the currently active HUD.Text fields allow the player to type text input. When the value changes,
HUD.onUIInteraction(String, Object)is triggered with the key and the text string.- Parameters:
name- unique key for the text fieldskinName- name of the skin to usex- X position in HUD coordinatesy- Y position in HUD coordinateswidth- text field widthheight- text field heightmessageText- initial message that is shown- Throws:
RuntimeException- if the specified skin cannot be foundIllegalStateException- if no active HUD is available or HUD is disabled
-
addSelectBox
public static void addSelectBox(String name, String skinName, float x, float y, float width, float height, String... items) Adds aSelectBox(drop-down menu) to the currently active HUD.Select boxes let players choose from a list of predefined options. When the selected option changes,
HUD.onUIInteraction(String, Object)is called with the selected value (String).- Parameters:
name- unique key for the select boxskinName- name of the skin to usex- X position in HUD coordinatesy- Y position in HUD coordinateswidth- select box widthheight- select box heightitems- array of selectable items- Throws:
RuntimeException- if the specified skin cannot be foundIllegalStateException- if no active HUD is available or HUD is disabled
-
addLabel
Adds a staticLabelto the currently active HUD.Labels display read-only text on the screen, useful for titles or indicators. They do not trigger any
HUD.onUIInteraction(String, Object)events.- Parameters:
name- unique key for the labelskinName- name of the skin to usex- X position in HUD coordinatesy- Y position in HUD coordinatestext- text to display- Throws:
RuntimeException- if the specified skin cannot be foundIllegalStateException- if no active HUD is available or HUD is disabled
-
addProgressBar
public static void addProgressBar(String name, String skinName, float x, float y, float width, float height, float min, float max, boolean vertical, float value) Adds aProgressBarto the currently active HUD.The progress bar is a visual indicator of a value between
minandmax.- Parameters:
name- unique key for the progress barskinName- name of the skin to usex- X position in HUD coordinatesy- Y position in HUD coordinateswidth- progress bar widthheight- progress bar heightmin- minimum value of the progress barmax- maximum value of the progress barvertical- true if the bar should be vertical, false if horizontalvalue- initial value of the progress bar- Throws:
RuntimeException- if the specified skin cannot be foundIllegalStateException- if no active HUD is available or HUD is disabled
-
getTextFieldValue
Returns the current text of aTextField.- Parameters:
name- unique element key- Returns:
- the text currently in the field
- Throws:
IllegalArgumentException- if no TextField exists with this key
-
setTextFieldValue
Sets the text of aTextField.- Parameters:
name- unique element keyvalue- text value to set- Throws:
IllegalArgumentException- if no TextField exists with this key
-
getCheckBoxValue
Returns whether aCheckBoxis currently checked.- Parameters:
name- unique element key- Returns:
trueif checked,falseif unchecked- Throws:
IllegalArgumentException- if no CheckBox exists with this key
-
setCheckBoxValue
Sets the checked state of aCheckBox.- Parameters:
name- unique element keychecked- true to check the box, false to uncheck it- Throws:
IllegalArgumentException- if no CheckBox exists with this key
-
getSliderValue
Returns the current value of aSlider.- Parameters:
name- unique element key- Returns:
- the slider's current float value
- Throws:
IllegalArgumentException- if no Slider exists with this key
-
setSliderValue
Sets the value of aSlider.- Parameters:
name- unique element keyvalue- new value for the slider- Throws:
IllegalArgumentException- if no Slider exists with this key
-
getSelectBoxValue
Returns the currently selected item of aSelectBox.- Parameters:
name- unique element key- Returns:
- the selected string item
- Throws:
IllegalArgumentException- if no SelectBox exists with this key
-
setSelectBoxValue
Sets the selected item of aSelectBox.- Parameters:
name- unique element keyvalue- the item to select, must be one of the box's available items- Throws:
IllegalArgumentException- if no SelectBox exists with this key
-
getLabelValue
Returns the text of aLabel.- Parameters:
name- unique element key- Returns:
- the text displayed by the label
- Throws:
IllegalArgumentException- if no Label exists with this key
-
setLabelValue
Sets the text of aLabel.- Parameters:
name- unique element keyvalue- new text to display- Throws:
IllegalArgumentException- if no Label exists with this key
-
getProgressBarValue
Retrieves the current value of aProgressBaron the active HUD.- Parameters:
name- unique key of the progress bar- Returns:
- current value of the progress bar
- Throws:
IllegalArgumentException- if no progress bar with the specified name exists
-
setProgressBarValue
Sets the value of aProgressBaron the active HUD.- Parameters:
name- unique key of the progress barvalue- new value to set; will be clamped to the progress bar's min and max- Throws:
IllegalArgumentException- if no progress bar with the specified name exists
-