BBMOD_AnimationState

Extends BBMOD_State
Implements Struct.BBMOD_IEventListener

constructor

new BBMOD_AnimationState(_name, _animation[, _loop])

Description

A state of an animation state machine.

Arguments

Name Type Description
_name String The name of the state.
_animation Struct.BBMOD_Animation The animation played while the is active.
_loop Bool If true then the animation will be looped. Defaults to false.

Properties

Name Description
Animation The animation played while the state is active.
Loop If true then the animation is played in loops.

Example

The following code shows examples of animation states which together make a simple locomotion state machine.

stateIdle = new BBMOD_AnimationState("Idle", animIdle, true);
stateIdle.OnUpdate = method(self, function () {
    if (in_air())
    {
        animationStateMachine.change_state(stateJump);
        return;
    }
    if (speed > 0)
    {
        animationStateMachine.change_state(stateWalk);
        return;
    }
});
animationStateMachine.add_state(stateIdle);

stateWalk = new BBMOD_AnimationState("Walk", animWalk, true);
stateWalk.OnUpdate = method(self, function () {
    if (in_air())
    {
        animationStateMachine.change_state(stateJump);
        return;
    }
    if (speed == 0)
    {
        animationStateMachine.change_state(stateIdle);
        return;
    }
});
animationStateMachine.add_state(stateWalk);

stateJump = new BBMOD_AnimationState("Jump", animJump, true);
stateJump.OnUpdate = method(self, function () {
    if (!in_air())
    {
        animationStateMachine.change_state(stateLanding);
        return;
    }
});
animationStateMachine.add_state(stateJump);

stateLanding = new BBMOD_AnimationState("Landing", animLanding);
stateLanding.on_event(BBMOD_EV_ANIMATION_END, method(self, function () {
    animationStateMachine.change_state(stateIdle);
}));

See also

BBMOD_AnimationStateMachine

Do you find this page helpful?

Copyright © 2022, BlueBurn. Built on May 18, 2022 using GMDoc.