Hi Guys,
I have made few characters using the editor, all animations are looking cool. I am facing a problem to use them correctly mainly walk and jump animations. Though I am using the spine-runtimes-sample for now thinking may be my animations are not correct, but same case.
In my game I have got a joystick which moves the character, while the move is triggered I apply walk animation, in the mean time the player can jump too. Now the problem is move, walk are not synchronized, and jump doesn't work everytime, or it works after character finishes walking.
I am putting some of my implementations here, if any can help please.
//Initialization.
this->playerBody=SkeletonAnimation::createWithFile("spineboy.json","spineboy.atlas");
this->playerBody->setMix("walk", "jump", 0.2f);
//Joystick Move
void Player::move(cocos2d::Vec2 velocity, float dt){
Vec2 pos=this->playerBody->getPosition();
if (velocity.x > 0)
{
// move right
this->playerBody->getSkeleton()->flipX=1;
pos.x=pos.x+2.0;
auto move=MoveTo::create(0.0, pos);
this->playerBody->runAction(move);
anim_walk();
}
else if (velocity.x < 0)
{
// move left
this->playerBody->getSkeleton()->flipX=0;
pos.x=pos.x-2.0;
auto move=MoveTo::create(0.0, pos);
this->playerBody->runAction(move);
anim_walk();
}
}
//Walk animation
void Player::anim_walk(){
if(isJumping)return;
this->playerBody->setAnimation(0, "walk", false);
}
//Jump animation
void Player::anim_jump(){
isJumping=true;
spTrackEntry* jumpEntry = this->playerBody->addAnimation(0, "jump", false);
this->playerBody->setTrackStartListener(jumpEntry, [&] (int trackIndex) {
log("jumped!");
isJumping=false;
});
}
Problems are
1. While the player is moving by joystick it slides then animates
2. I tried to use addAnimation for walk, it works fine, but if I stop moving the animation doesn't stop, it stop after sometime, its understandable that it is adding animations, to it is executing in queue
How to solve these problems, I know that I am doing some mistake in implementations, tried many things, not able to find correct way.
Thanks for help.