TNTAnimationController - UQcsse3200/2023-studio-3 GitHub Wiki
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
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);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>");
}-
"defaultStart" Event
- Event Listener:
this::animateDefault - Sprite Sheet: 1 frame for
defaultanimation
- Event Listener:
-
"digStart" Event
- Event Listener:
this::animateDig - Sprite Sheet: 7 frames for
diganimation

- Event Listener:
-
"explodeStart" Event
- Event Listener:
this::animateExplode - Sprite Sheet: 7 frames for
explodeanimation

- Event Listener:
- Make sure to initialize and add an
AnimationRenderComponentto the entity before addingTNTAnimationController. - Clearly define your animation states in the
AnimationRenderComponentfor seamless transitions between animations. - Ensure the event names used in
TNTCombatTaskandTNTAnimationControllerare synchronized to keep the game logic and animations in harmony.
Please refer to the TNTAnimationController Test Plan for detailed test cases and methodologies.