setAnimation
takes 3 parameters, not 4:
player.animationState.setAnimation(0, "run", true, 5);
addAnimation
takes 4 parameters, not 3:
player.animationState.addAnimation(0, "jump", false); // Missing the delay param.
Make sure you understand the parameters (read the docs).
The true
being passed makes that animation loop if playback exceeds the animation duration. If false
is passed it will give you the last frame forever.
It's easy to play a single animation looping forever. To play multiple animations repeatedly, you'll need a listener to know when they are done, then you set the animations again:
success: function (player) {
var loop = function () {
player.animationState.addAnimation(0, "jump", true, 0);
var entry = player.animationState.addAnimation(0, "run", true, 3);
entry.listener = {
complete: function (event) {
loop();
}
};
};
loop();
},
There are other events available beside complete
, see the API reference docs.
You can also mix between animations, so the change is not so abrupt:
player.animationState.data.defaultMix = 0.2;
player.animationState.addAnimation(0, "jump", true, 0);
Or on a specific transition:
var entry = player.animationState.addAnimation(0, "jump", true, 0);
entry.mixDuration = 0.2;