Skip to content

Alien Fauna ‐ Animations

pchsa edited this page Oct 3, 2023 · 8 revisions

Animations

The animations for all the animals currently are handled by the AnimalAnimationController. To add an animation to an animal using this controller, first add the animation to the AnimationRenderComponent, then add an event listener for it in the create method and then create an accompanying method that calls startAnimation on the AnimationRenderComponent.

Here is an example of what a AnimalAnimationController's create method could look like with an accompanying animateWalk method.

@Override
public void create() {
        entity.getEvents().addListener("walkStart", this::animateWalk);
    }

    void animateWalk() {
        animator.startAnimation("walk");
    }

In our code, each animation has both a left and right version to match the direction the animal is walking. To account for this in the code, each animation follows the naming scheme <animation_name>_ where direction is left or right e.g., 'walk_right'. The animate methods that call the startAnimation on the AnimationRenderComponent in the AnimalAnimationController follow a certain pattern to accomodate this.

Here is the animateRun method.

    void animateRun() {
        animator.startAnimation(RUN_PREFIX + "_" + direction);
        currentAnimation = RUN_PREFIX;
    }

A prefix (in this case RUN_PREFIX) is defined here as is the case cross all animation methods.direction is a variable that is set according to the direction the animal is moving and will update as needed. This design pattern was chosen as it reduces duplication (no need for left and right variation of method) and is simple to understand and replicate.

Hostiles

Hostile animals use HostileAnimationController instead. It inherits from AnimalAnimationController but also requires an attack animation. Triggering the animation using entity.getEvents().trigger("attackStart") will override the existing animation. Once the attack animation is finished, it will play the current movement animation (idle, walk, run).

System Overview

The animal animations are handled by the following components. image

Clone this wiki locally