-
Notifications
You must be signed in to change notification settings - Fork 9
Interact Label
First see UI.
The InteractLabel is a UI component designed to display interaction prompts to the player in the game. It provides visual cues to inform the player about interactive actions they can take, enhancing the user interface and overall gaming experience.
The primary purpose of the InteractLabel is to create a visual indicator, often in the form of a label with an action button icon, to guide players on how to interact with objects or characters within the game world. This component is particularly useful for providing clear and intuitive instructions for in-game interactions.
The InteractLabel class provides two constructors for creating interaction labels:
This constructor creates an interaction label with a default "Press F to interact" message and a blinking animation for the F button icon.
public InteractLabel()
This constructor allows you to customize the interaction label with a specified label message and a custom position on the screen.
public InteractLabel(String label, Vector2 position)
To effectively use the InteractLabel in your game, follow these steps:
-
Create an InteractLabel Instance : Instantiate an
InteractLabel
object using either the default or custom constructor, depending on your requirements.
// Create an interaction label with the default "Press F to interact" message.
InteractLabel interactLabel = new InteractLabel();
// OR
// Create a custom interaction label with a specific message and position.
InteractLabel customInteractLabel = new InteractLabel("Custom message", new Vector2(x, y));
-
Set up Skin and Style: The
InteractLabel
relies on a Skin and style for its appearance. Make sure to configure the skin and style used by the label. In the example provided, the skin is loaded from a JSON file. -
Position the Label: Use the
setPosition()
method to specify the position of the interaction label on the screen. -
Visibility Control: You can control the visibility of the label using the
setVisible()
method. This allows you to show or hide the label based on the game's logic. -
Blinking Animation: The default constructor creates a blinking animation for the F button icon. This animation improves the visual appeal of the interaction prompt and ensures it grabs the player's attention.
Here's a simple example demonstrating how to use the InteractLabel
to display an interaction prompt to the player:
InteractLabel interactLabel = new InteractLabel();
// Position the label at the center of the screen.
interactLabel.setPosition((stage.getWidth() - interactLabel.getWidth()) / 2, 80);
// Make the label visible.
interactLabel.setVisible(true);
// Add the label to the game's stage for rendering.
stage.addActor(interactLabel);
By following these steps, you can seamlessly integrate the InteractLabel
into your feature's user interface to provide clear and engaging interaction instructions for players. This component ensures that players are aware of available interactions and contributes to a more immersive gaming experience.
Escape Earth Game
Interaction Controller and Interactable Components
Game and Entity Configuration Files
Loading Game Configuration Files