• Runtimes
  • Simple how-to question

  • Modificato
Related Discussions
...

Hi!

I see I may Mix from one animation to another. I found example in docs:

Combining animations
Multiple animations can be applied in sequence to animate parts of the skeleton differently:

Skeleton skeleton = new Skeleton(skeletonData);
AnimationState state1 = new AnimationState(stateData);
state1.setAnimation("walk", true);
AnimationState state2 = new AnimationState(stateData);
state2.setAnimation("shoot", false);
...
function render (float delta) {
   state1.update(delta);
   state2.update(delta);
   state1.apply(skeleton);
   state2.apply(skeleton);
   skeleton.updateWorldTransform();
   renderSkeleton(skeleton);
}

But how can I do it in cocos2d-x??
I am unable to understand where to find mentioned "apply" and "update"... Looks like documentation are far away from cocos2d-x classes. I was able to play and mix animations this way:

auto skela = static_cast<spine::SkeletonAnimation*>(&*ii);
				
spAnimation* animation = spSkeletonData_findAnimation(skela->skeleton->data, an.c_str() );
				
if (animation!=nullptr)
{
	spTrackEntry* pres = skela->setAnimation(0, an.c_str(), false);

if (randomize)
{
    skela->update(rand() % int(pres->endTime * 1000) / 1000.0);
}
}

Please assist.

Thanks!

Am I right if I say - adding annimations to different tracks means both animations will play simultaneously?
If yes, are there any option to set weight for a track? For cases when different animations have influence for same bones.

Yes, animations on different tracks are both applied each frame.

No, there currently isn't a way to set the weight of an AnimationState track. The lower track numbers are applied first. Higher track numbers that key the same bone will overwrite the value from the lower tracks.

AnimationState is meant to be a convenience to handle the most common animation needs. It uses the lower level Animation API. Using that, it is possible to mix animations however you like. Eg, Animation#mix() allows you to apply an animation by combining the animation's pose with whatever the pose the skeleton currently has. mix() takes an "alpha" parameter which is from 0 to 1 and is the amount the animation affects the current pose, where 1 means overwrite the current pose completely. AnimationState uses this to blend from one animation to the next for a single track, but doesn't use it to combine tracks.

Do you expect ease to use weghts/alpha for tracks in nearest future?

PS: Be proud - Spine is awesome. We expect to achieve great results using it.

I found a way to integrate the feature into AnimationState, now in git. It works like this:

state.setAnimation(0, "walk", true);
TrackEntry entry = state.setAnimation(1, "jump", true);
entry.mix = 0.4f;

Or:

state.setAnimation(0, "walk", true);
state.setAnimation(1, "jump", true).mix = 0.4f;

Each frame, walk will be applied on track 0, then jump will be applied on track 1 with a mix of 0.4, meaning it will use 60% of whatever pose is the result of the previous tracks (here will be the walk pose) and 40% of the jump animation. If mix isn't set 1 is used, meaning overwrite any previous tracks. As before, only keyed properties are affected by an animation.

Note you can keep a reference to the TrackEntry and change the mix over time as you wish to get various mixing effects. Though with spine-c be careful not to use the TrackEntry after it is disposed by AnimationState.

AAA oooo.

I hope I will have a chance to fill you with finest beer 🙂

PS: tomorrow I will find someone in office to pull that Git out. I am too old for all these fancy modern technologies 🙂

Had no a chance to look into it 🙁

Questions:
what is best for perfomance if I need to hide some parts of animated skeleton: alpha, remove bitmap or there is more interesting things?

PS: for editor it will be superrior if there will be a chance to play different animations on the background to emaulate runtime traks feature.

Making alpha zero with not improve performance. Just turn off the image in the slot if you want to hide it for long periods of time.

Oh excellent. I was just wanting this myself. Looks like I gotta update my runtimes. 🙂

EDIT: Cool, I think it's working (C Runtime). Of course I had to push it beyond 100% too: https://vine.co/v/MqVp5zPMEqQ