Extends BBMOD_StateMachine
constructor
new BBMOD_AnimationStateMachine(_animationPlayer)
A state machine that controls animation playback.
Name | Type | Description |
---|---|---|
_animationPlayer | Struct.BBMOD_AnimationPlayer |
The animation player to control. |
Name | Description |
---|---|
AnimationPlayer | The state machine's animation player. |
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 = animationPlayer.destroy();
animationStateMachine = animationStateMachine.destroy();
BBMOD_AnimationPlayer, BBMOD_AnimationState
Copyright © 2023, BlueBurn. Built on February 04, 2023 using GMDoc.