To play animations, you first need to load your animated character like usually:
/// @desc Create event
modCharacter = new BBMOD_Model("Data/Character.bbmod");
and assign it materials that support animations:
matCharacter = BBMOD_MATERIAL_DEFAULT_ANIMATED.clone();
matCharacter.BaseOpacity = sprite_get_texture(SprCharacter, 0);
modCharacter.set_material("Material", matCharacter);
Then you need to create a BBMOD_AnimationPlayer for the model:
animationPlayer = new BBMOD_AnimationPlayer(modCharacter);
To load the actual animation data, use struct BBMOD_Animation:
animIdle = new BBMOD_Animation("Data/Character_Idle.bbanim");
animWalk = new BBMOD_Animation("Data/Character_Walk.bbanim");
BBMOD_AnimationPlayer
has a method play
which starts playing an animation from the beginning. When dealing with changing
animations, it is a lot easier to use the method
change, which keeps track of which
animation it was playing and every time you pass it a different animation it
automatically transitions into it. The animation update itself is performed in
method update, so do not forget to call
that every frame for each animation player!
/// @desc Step event
var _animation = (speed > 0) ? animWalk : animIdle;
animationPlayer.change(_animation, true);
animationPlayer.update(delta_time);
To render the animated model, use method submit of the animation player:
/// @desc Draw event
bbmod_material_reset();
matrix_set(matrix_world, matrix_build(x, y, z, 0, 0, direction, 1, 1, 1));
animationPlayer.submit();
bbmod_material_reset();
Also do not forget to destroy the animation player before it gets out of scope, otherwise you will get memory leaks!
/// @desc Clean Up event
animationPlayer.destroy();
Copyright © 2022, BlueBurn. Built on April 11, 2022 using GMDoc.