- Modifié
[Libgdx] How to smoothly switch animations part way through?
Sorry if this has been asked before, I couldn't think of any good key words to use when searching the forum.
Lets say I'm animating a human.
I use Track 0 to animate him walking.
I use Track 1 to animate his arms.
I set Track 0 to a "walking" loop animation.
I use addEmptyAnimation on Track 1, and then addAnimation("raise arms") to Track 1, so that he smoothly starts to raise his arms.
Now my question is, if he is HALFWAY through his "raise arms" animation, and I need him to instead "clap hands", how can I do that? I'd like the smooth transition to be from wherever his arms currently are in the "raise arms" animation (halfway up, or wherever), straight into the "clap hands" animation.
Is there some way to say end the "raise arms" animation right where it is currently, such that I could then just addAnimation("clap hands")?
Thanks as always for the help :love:
You just use AnimationState setAnimation
to set track 1 to your clap hands
animation. AnimationState supports "multiple mixing", so the transition from empty to raise arms
continues to occur even while you mix to clap hands
. The clap hands
animation will take over more and more until the empty and raise arms
animations cannot be seen.
Note you use setAnimation
because you want to get rid of the animations that are currently queued right now and replace them with clapping. If you wanted the clapping to happen after the current animations (or after a delay), you'd use addAnimation
.
Thanks Nate! Makes total sense now 8)