Patrick Animation Controller - UQcsse3200/2023-studio-3 GitHub Wiki
The PatrickAnimationController is a specialized game component designed to manage and trigger animations for the Patrick Boss entity. This class listens to a variety of events that correspond to different states of the Patrick Boss such as walking, attacking, and dying. The actual triggering of these events is managed by Patrick Task.
To make use of the PatrickAnimationController, you must first attach this component to a Patrick Boss entity. Below is a Java code snippet demonstrating this process:
PatrickAnimationController animationController = new PatrickAnimationController();
patrick.addComponent(animationController);Additionally, an AnimationRenderComponent is required for the controller to function. Here's how to add it:
private static final String PATRICK_ATLAS = "images/mobboss/patrick.atlas";
TextureAtlas textureAtlas = ServiceLocator.getResourceService().getAsset(PATRICK_ATLAS, TextureAtlas.class);
AnimationRenderComponent animator = new AnimationRenderComponent(textureAtlas);
patrick.addComponent(animator);The PatrickAnimationController listens for events like "patrick_attack", "patrick_walk", "patrick_death", etc., which are triggered by other components. When an event is triggered, it initiates the corresponding animation on the Patrick Boss entity.
Here is the general way the controller listens for events:
entity.getEvents().addListener("<EventName>", this::<MethodName>);- Ensure an
AnimationRenderComponentis initialized and added to the entity before attachingPatrickAnimationController. - Clearly specify your animation states in the
AnimationRenderComponentfor smooth transitions between animations. - Make sure the event names used in the task logic component and
PatrickAnimationControllerare synchronized to maintain cohesive gameplay logic and animations.