Skip to content

TNTAnimationController

Mohamad Dabboussi edited this page Sep 11, 2023 · 4 revisions

TNTAnimationController Documentation

Overview

The TNTAnimationController is a game component responsible for orchestrating animations for the TNTTower entity. This class listens for a set of events which executes animations like digging, defaulting, and exploding. It receives these events of initiating the corresponding animations, and the actual triggering of these events is handled by TNTCombatTask

How To Use It

To use the TNTAnimationController, you must first add the component to a TNTTower entity. The following Java code demonstrates how to do so:

TNTAnimationController animationController = new TNTAnimationController();
tntTowerEntity.addComponent(animationController);

You'll also need an AnimationRenderComponent to which this controller will rely on:

TextureAtlas textureAtlas = ServiceLocator.getResourceService().getAsset(TNT_ATLAS, TextureAtlas.class);
AnimationRenderComponent animator = new AnimationRenderComponent(textureAtlas);
tntTowerEntity.addComponent(animator);

Example Usage

General Event Listening Mechanism

The TNTAnimationController listens for specific events like "defaultStart", "digStart", and "explodeStart", triggered by TNTCombatTask. When such an event is triggered, the corresponding animation is initiated on the TNTTower entity.

Here's how the controller listens for an event of executing an animation:

entity.getEvents().addListener("<EventName>", this::<MethodName>);
void <MethodName>() {
    animator.startAnimation("<AnimationName>");
}

Specific Event Examples

  1. "defaultStart" Event

    • Event Listener: this::animateDefault
    • Sprite Sheet: 1 frame for default animation
    Default Animation Frame
  2. "digStart" Event

    • Event Listener: this::animateDig
    • Sprite Sheet: 7 frames for dig animation

    image

  3. "explodeStart" Event

    • Event Listener: this::animateExplode
    • Sprite Sheet: 7 frames for explode animation

    image

Best Practices

  • Make sure to initialize and add an AnimationRenderComponent to the entity before adding TNTAnimationController.
  • Clearly define your animation states in the AnimationRenderComponent for seamless transitions between animations.
  • Ensure the event names used in TNTCombatTask and TNTAnimationController are synchronized to keep the game logic and animations in harmony.

Test Plan

Please refer to the TNTAnimationController Test Plan for detailed test cases and methodologies.

Clone this wiki locally