BBMOD_AnimationState

A constructor defined in BBMOD_AnimationState.gml

Extends BBMOD_State
Implements BBMOD_IEventListener

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.

Inherited properties

Name Description
IsActive If true then the state is currently active.
Name The name of the state.
OnEnter A function executed when a state machines enters this state. Should take the state as the first argument. Default value is undefined.
OnExit A function executed when a state machine exists this state. Should take the state as the first argument. Default value is undefined.
OnUpdate A function executed while the state is active. Should take the state as the first argument and delta time as the second. Default value is undefined.
StateMachine The state machine to which this state belongs or undefined.

Methods

Name Description
off_event Removes event listeners.
on_event Adds a listener for a specific event.
trigger_event Triggers an event in the event listener.

Inherited methods

Name Description
get_duration Retrieves how long (in milliseconds) has the state been active for.

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_Animation, BBMOD_AnimationInstance, BBMOD_AnimationPlayer, BBMOD_AnimationStateMachine

Do you find this page helpful?

Copyright © 2024, BlueBurn. Built on September 07, 2024 using GMDoc.