-
Notifications
You must be signed in to change notification settings - Fork 4
ButtonFactory
Here is a draft wiki page in Markdown format for the ButtonFactory class:
The ButtonFactory class provides static utility methods for creating TextButton UI components with different styles in a LibGDX game.
To use the ButtonFactory, simply call one of the static create methods, passing the button text and other parameters:
TextButton button = ButtonFactory.createButton("Play");
This will create a TextButton with the default style using the default skin.
The ButtonFactory has methods to create buttons with:
- The default style
- A custom image
- An image loaded from a TextureAtlas
Creates a TextButton with the specified text using the default skin and style.
-
text
- The text to display on the button
Creates a custom TextButton with the specified text and custom image.
-
text
- The text to display -
imagePath
- Path to the custom button image
Creates a custom TextButton loading the button image from a TextureAtlas.
-
text
- The text to display -
atlasPath
- Path to the TextureAtlas
The ButtonFactory initializes a default skin on startup that provides the button style, font, etc.
The default skin loads the font from configs/text.json
and sets the button background image to images/ui/Sprites/UI_Glass_Button_Large_Lock_01a1.png
.
The create methods that don't specify a custom image will use this default skin and style.
To create a button with a custom image, use the createCustomButton()
method, passing the path to your custom PNG image.
To use images packed into a TextureAtlas, use createCustomButtonWithAtlas()
, passing the atlas file path. This allows sharing images across multiple buttons.
All buttons created clamp the font scale to 0.8f by default to make the text legible.
A padding of 10px is applied to all buttons by default.
// Default button
TextButton playBtn = ButtonFactory.createButton("Play");
// Custom image button
TextButton exitBtn = ButtonFactory.createCustomButton("Exit", "images/buttons/exit.png");
// Button from texture atlas
TextButton nextBtn = ButtonFactory.createCustomButtonWithAtlas("Next", "images/ui/atlas.atlas");
This provides a flexible way to create text buttons with custom styles and images for a game UI using LibGDX.