Skip to content

Player Animations

liv edited this page Aug 29, 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. 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");
}

Interaction with Other Components

A summary of the interactions between components inside a Player entity instance is shown in the class diagram below. image

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.

PlayerAnimationEvents

Clone this wiki locally