BBMOD_AnimationStateMachine

Extends BBMOD_StateMachine

constructor

new BBMOD_AnimationStateMachine(_animationPlayer)

Description

A state machine that controls animation playback.

Arguments

Name Type Description
_animationPlayer Struct.BBMOD_AnimationPlayer The animation player to control.

Properties

Name Description
AnimationPlayer The state machine's animation player.

Example

Following code shows an animation state machine which goes to the "Idle" state on start and independently on the current state switches to "Dead" state when variable hp meets 0. After the death animation ends, the state machine enters the final state and the instance is destroyed.

// Create event
destroy = false;
animationPlayer = new BBMOD_AnimationPlayer(model);

animationStateMachine = new BBMOD_AnimationStateMachine(animationPlayer);
animationStateMachine.OnEnter = method(self, function () {
    animationStateMachine.change_state(stateIdle);
});
animationStateMachine.OnExit = method(self, function () {
    destroy = true;
});
animationStateMachine.OnPreUpdate = method(self, function () {
    if (hp <= 0 && animationStateMachine.State != stateDead)
    {
        animationStateMachine.change_state(stateDead);
    }
});

stateIdle = new BBMOD_AnimationState("Idle", animIdle);
animationStateMachine.add_state(stateIdle);

stateDead = new BBMOD_AnimationState("Dead", animDead);
stateDead.on_event(BBMOD_EV_ANIMATION_END, method(self, function () {
    animationStateMachine.finish();
}));
animationStateMachine.add_state(stateDead);

animationStateMachine.start();

// Step event
animationStateMachine.update();
if (destroy)
{
    instance_destroy();
}

// Clean Up event
animationPlayer.destroy();
animationStateMachine.destroy();

See also

BBMOD_AnimationPlayer, BBMOD_AnimationState

Do you find this page helpful?

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