-
Notifications
You must be signed in to change notification settings - Fork 1
Main Character Statistics
PlayerStatsDisplay is a UI component in the game that manages and displays player statistics, including health, experience, and hunger. This class is a part of the game's UI system, utilizing LibGDX for rendering and animation.
Display Player Stats: The class is responsible for displaying the player's health, experience, and hunger stats on the screen. Manage Animations: Handles the animations for health, experience, and hunger bars, updating them in real-time based on player stats. UI Setup: Creates and positions UI elements like labels and images on the game stage.
Attributes:
Table table: Used to organize the layout of the UI components. Image healthImage, xpImage, hungerImage: Displays the health, experience, and hunger bars. Label healthLabel, experienceLabel, hungerLabel: Displays numerical values for health, experience, and hunger. Animation healthBarAnimation, hungerBarAnimation, xpBarAnimation: Manages the frame-based animation for the bars. TextureAtlas[] textureAtlas: Holds the texture atlases used for loading the sprite sheets of the bars. Methods:
create(): Initializes the component and sets up event listeners. initBarAnimations(): Initializes animations for the health, hunger, and experience bars. addActors(): Adds the UI elements (images and labels) to the stage. setNewFrame(int frameIndex, Animation statBarAnimation, Image statBar): Updates the frame of a given stat bar. updatePlayerHealthUI(int health): Updates the health bar and label based on the current player health. updatePlayerHungerUI(int hunger): Updates the hunger bar and label. updatePlayerExperienceUI(int experience): Updates the experience bar and label. dispose(): Cleans up resources when the component is no longer needed. Usage Example To use the PlayerStatsDisplay class, it should be instantiated and added to the game's UI system. The class automatically updates the player stats as they change in the game.
PlayerStatsDisplay statsDisplay = new PlayerStatsDisplay();
statsDisplay.create();
Event Handling
The class listens for the following events:
updateHealth: Triggers updatePlayerHealthUI(int health) to update the health bar and label. updateExperience: Triggers updatePlayerExperienceUI(int experience) to update the experience bar and label. updateHunger: Triggers updatePlayerHungerUI(int hunger) to update the hunger bar and label. Dependencies LibGDX: The class heavily relies on LibGDX libraries for rendering, animations, and UI layout. ServiceLocator: Used to retrieve the rendering service and stage. Disposing Resources The dispose() method ensures that all resources such as texture atlases and UI elements are properly disposed of to prevent memory leaks.
Test Plan: Main Character Statistics Test Plan