Skip to content

Player Animations

liv edited this page Aug 16, 2023 · 3 revisions

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.

Usage

Once an animation is added to the player.atlas file, it needs to be registered in the PlayerFactory setupPlayerAnimator() function.

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");
}
Clone this wiki locally