Hi,
I trying to create two animation that can switch between each other. To be more specific, i have a running animation with 5 sprites (1->2->3->4->5) and running attack also 5 sprites (1a->2a->3a->4a->5a). So i want that when player are running and the running animation is at sprite 3, player press attack and the sprite will change to 3a or 4a next. Is this possible?
Currently when switch between running to running attack mid animation, i can only do 1->2->3->1a->2a->… It created a little glitch on animation as the sprite 1a reset animation.
Here’s my code.
Animate *run;
Animate *running_attack;
void setupRunAnimation()
{
if (run!= NULL)
run->release();
run= Animate::create(AnimationCache::getInstance()->getAnimation("run"));
run->startWithTarget(this);
run->setDuration(0.5f);
run->retain();
}
void setupRunningAttackAnimation()
{
if (running_attack!= NULL)
running_attack->release();
running_attack= Animate::create(AnimationCache::getInstance()->getAnimation("running_attack"));
running_attack->startWithTarget(this);
running_attack->setDuration(0.5f);
running_attack->retain();
}
void updatePlayerState(float delta)//update player state every frame
{
if (state == running)
{
if (run == NULL || run->isDone())
run->startWithTarget(this);
run->step(delta);
}
else if (state == attacking)
{
if (running_attack == NULL || running_attack->isDone())
running_attack->startWithTarget(this);
running_attack->step(delta);
}
}