-
Notifications
You must be signed in to change notification settings - Fork 7
Player Animations
The PlayerAnimationController
class is used to handle listending to events on the player entity and playing the correct animations when an event is triggered. Animations should be added to the player.atlas
file and registered in the PlayerFactory
.
Once an animation is added to the player.atlas
file, it needs to be registered in the PlayerFactory
setupPlayerAnimator()
function. See Animations for more info on setting up an animation.
animator.addAnimation("walk_stop", 0.1f, Animation.PlayMode.LOOP);
An event listener can then be added in the PlayerAnimationController
create()
function. See Event System for more info on events.
entity.getEvents().addListener("animationWalkStop", this::animationWalkStop);
The listener can then handle playing the animation when it is called:
void animationWalkStop() {
animator.startAnimation("walk_stop");
}
A summary of the interactions between components inside a Player entity instance is shown in the class diagram below.
The animations are triggered primarily as a result of user input. An example of the flow of events when the key "a" is pressed is shown below.