Skip to content

Action Feedback Component

yuvrajsingh001 edited this page Oct 5, 2023 · 2 revisions

First see Components.

The ActionFeedbackComponent is a vital component in our game development project responsible for generating action feedback alerts based on entity events. These alerts are visually distinctive and are created using the AlertUIComponent.

Purpose

The primary purpose of the ActionFeedbackComponent is to create and display customizable warning alerts in response to specific events or actions within the game. These alerts help convey important information, warnings, or notifications to the player, enhancing the overall gaming experience.

Constructors

The ActionFeedbackComponent class does not have any custom constructors as it inherits from the Component class, and its initialization is handled by the parent class.

Usage

To effectively use the ActionFeedbackComponent, follow these steps:

  1. Create an Entity with ActionFeedbackComponent: Instantiate an entity in the game and add the ActionFeedbackComponent to it. This component will enable you to trigger and display custom warning alerts on this entity.

    Entity yourEntity = new Entity();
    yourEntity.addComponent(new ActionFeedbackComponent());
  2. Adding Event Listeners: The ActionFeedbackComponent automatically adds event listeners to the entity. Two specific events can be used to trigger alerts:

    • "displayWarning": Displays an alert at the entity's current position.
    • "displayWarningAtPosition": Displays an alert at a specified position.

    You can trigger these events to display alerts as needed:

    // Display a warning alert at the entity's current position.
    yourEntity.getEvents().trigger("displayWarning", "Your alert message here");
    
    // OR
    
    Vector2 position = new Vector2(x, y); // Specify the position where the alert should be displayed.
    yourEntity.getEvents().trigger("displayWarningAtPosition", "Your alert message here", position);
  3. Customization: The alerts displayed by the ActionFeedbackComponent are created using the AlertUIComponent. You can customize the appearance and behavior of these alerts by modifying the properties of the AlertUIComponent. This includes changing text color, background color, and other visual aspects.

Example

Here's a simple example demonstrating how to use the ActionFeedbackComponent to create and display a warning alert:

Entity playerEntity = new Entity();
playerEntity.addComponent(new ActionFeedbackComponent());

// Trigger a warning alert at the player's current position.
playerEntity.getEvents().trigger("displayWarning", "Dangerous area ahead!");

By following these steps, you can seamlessly integrate the ActionFeedbackComponent into your feature, providing informative and visually appealing alerts to enhance the player's gaming experience, all powered by the AlertUIComponent.

Clone this wiki locally