- संपादित
switch animation quickly between two different animation
when i quickly switch different animation, skeleton will have a strange phenomenon
push test1 skeleton will run walk animation
push test2 skeleton will run jump animation
here is normal state
but when i push test2 button, skeleton will run jump animation, when skeleton jump animation running in this state
i push test1 quickly which will run walk animation, but skeleton have a strange phenomenon state in running walk animation. skeleton slight tilt to one side when he is running walk animation.
here is my code:
void ExampleLayer::test1(cocos2d::CCObject *obj)
{
skeletonNode->clearTrack();
skeletonNode->setAnimation(0, "walk", true);
}
void ExampleLayer::test2(cocos2d::CCObject *obj)
{
skeletonNode->clearTrack();
skeletonNode->setAnimation(0, "jump", true);
}
anyone have an idea?
Please read this:
http://esotericsoftware.com/spine-using ... on-changes
This must be some sort of record, this same exact issue has come up 3 times today! I know it is a little tricky, but it needs to work that way. I should really finish making a FAQ so people can get help more easily.
Just to make sure I understand what you're seeing:
1) You switch from walk to jump, and it looks good.
2) You switch from jump back to walk, and he's now walking at an odd angle.
Is that right? If so, then (as Nate wrote) everything is working properly.
I ran into this too, and thought I'd messed something up on my end. This is caused by the root bone being rotated during the jump animation, but there are no rotation keys set for the walk animation. You can easily fix this by setting at Rotate 0.0 key on the first frame of the walk animation, or you can modify the jump animation to remove rotations from the root bone. (I prefer to rotate from hip bone instead and always keep the root unmodified.)
Please let me know if this doesn't make sense.
Also, nice work on those docs, Nate. First time I've seen that, and it's quite excellent.
nice, but i think when we run clearTrack() method, it should clean current animation every state which include rotations.
clearTrack() only changes what animation is current for a track. It doesn't affect the skeleton's pose.
@Chounard it doesn't work right, when i set skeleton root bone rotation to 0.0 before i set a walk animation. it also walking at an odd angle.
here is my test code, it that right?
void ExampleLayer::test1(cocos2d::CCObject *obj)
{
skeletonNode->rootBone->rotation = 0;
skeletonNode->setToSetupPose();
skeletonNode->setAnimation(0, "walk", true);
}
I would have expected that to work, but I'm not fully sure what's going on under the hood.
What I was suggesting you change is the actual animation itself. (In the Spine application, just set a rotation keyframe in the walk animation.)
setToSetupPose should do it. You sure it is being called?
Doesn't seem to (at least when animating with AnimationState.)
I just replaced the Update method in the XNA example with this (C# code):
KeyboardState oldState;
bool jumping = false;
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
KeyboardState ks = Keyboard.GetState();
if (!oldState.IsKeyDown(Keys.Space) && ks.IsKeyDown(Keys.Space))
{
if (jumping)
{
state.SetAnimation(0, "walk", true);
skeleton.SetToSetupPose();
}
else
{
state.SetAnimation(0, "jump", false);
skeleton.SetToSetupPose();
}
jumping = !jumping;
}
oldState = ks;
base.Update(gameTime);
}
Hit space to switch between walk and jump. (He starts in the drawOrder animation, in the current example.) When you switch to jump, hit space again quickly, and you'll see him walking at an angle.
Ah, right. It is mixing (crossfading) the jump and walk animation, so it continues to apply the jump animation, which rotates the root bone. Some time later when the crossfade is done the root bone is still rotated. So if using setBonesToSetupPose or setToSetupPose you can't use crossfading.