Nate schriebThe mix time (crossfade time) is defined by AnimationStateData.
@Nate - Got it working. Sorry about the start of this thread. I was confused that the examples in the documentation were asking users to write the code in the render() function. After consulting other examples, like Applying Animations I finally realized that isn't what the doc was indicating, instead it was including the render() as an educational point (i.e. this is what the runtime does). I got hung up, as I didn't want to have to write the render code 😉 Clearly, you've done that already!
Here is the example code that would have helped me without having to post on the boards:
// create a new spine skeleton
Skeleton skeleton = new Skeleton(skeletonData);
// animation state data will maintain information about cross fades
AnimationStateData stateData = new AnimationStateData(skeletonData);
// when we transition from walk to jump, crossfade in 0.2f seconds
stateData.setMix("walk", "jump", 0.2f);
// when we transition from jump to walk, crossfade in 0.4f seconds
stateData.setMix("jump", "walk", 0.4f);
// instruct the new spine skeleton to use this animation data
skeleton->setAnimationStateData(stateData);
// now, whenever an animation is set or added, smooth crossfades are applied
skeleton->setAnimation(0, "walk", true);
// later
skeleton->addAnimation(0, "jump", false);
Crossfade is now working great for me. I have one occasion where we control the rotation of a bone before an animation with code, but when I add an AnimationStateData object into the picture, the code-driven rotation stops happening. If I stop calling skel->setAnimationStateData(stateData) it starts working again.
I am okay if this is the case
we won't use cross-fade on that spine and it will just be a little jumpy. But I was curious if there is a solution I am missing.
spine::SkeletonAnimation* skel = getSkeleton(...);
// get the bone we need to rotate
spBone* defenseGun = skel->findBone("Defense Gun");
// calculate the rotation angle
float rotationCalc = ... // math here
// rotation the bone manually
defenseGun->rotation = rotationCalc;
// update the SRT after the rotation
skel->updateWorldTransform();
// also tried this, but didn't work
spBone_updateWorldTransform(defenseGun);