Switching between two Animations

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);
	}
}

Hi, did you try to pause/resume the action before switching to the other animation?
There’s a getCurrentFrameIndex() but unfortunately no setCurrentFrameIndex. So AFAIK there’s no easy way to do it.

Did you mean when the first animation is running 1->2->3 player use attack and the animation pause at sprites 3 and switch to second animation? But then the second animation will still start at 1a not 3a or 4a.

Is it possible to run 2 animation at the same time but the sprite can choose and use one based on player state?
For example if player’s state is running, sprite will run first animation, but the second animation also running bellow and player won’t see it. If player attack then second animation will go up and first go down but both still running at the same time.

I was suggesting to pause the animation to fix the glitch.

But then the second animation will still start at 1a not 3a or 4a.

Why not split the animation then? [1a,2a,3a] [4a,5a,6a].

Is it possible to run 2 animation at the same time but the sprite can choose and use one based on player state?

I don’t think so, but you can run the animations against different sprites and only show/hide the sprites as needed.