Cocos2d CCActionSequence order and delay messed up

439 Views Asked by At

I'm working on cocos2d V3.x project (SpriteBuilder V1.2.1). Currently trying to run this action sequence with a delay on a CCSprite. I'm not sure if there is a problem or maybe I just don't understand how CCActionSequence works.

I want action 'a' to start, when finished (after 2s) a delay (of 5s) and then both functions are called (actions 'c' and 'd'). But in the simulator the order is wrong ('d' is called before 'c') and they are called approximately 1s after 'a' starts rotating.

Am I doing anything wrong? If this is the actual way CCActionSquence works, what can I do to make it work the way I explained in the previous paragraph?

CCAction *a = [CCActionRotateBy actionWithDuration:2 angle:360];
CCAction *b = [CCActionDelay actionWithDuration:5];
CCAction *c = [CCActionCallFunc actionWithTarget:self selector:@selector(limpiarSeleccionadas)];
CCAction *d = [CCActionCallFunc actionWithTarget:self selector:@selector(endTurn)];
[[_arregloBolitas objectAtIndex:random] runAction:[CCActionSequence actionWithArray:@[a,b,c,d]]];

Thanks!

1

There are 1 best solutions below

2
Jake Lin On

You can put action 'c' and 'd' in CCSpawn, and then they will run at the same time. Also use CCDelayTime to delay the last two actions.

Please try this

CCAction *a = [CCActionRotateBy actionWithDuration:2 angle:360];
CCAction *b = [CCDelayTime actionWithDuration:5];
CCAction *c = [CCCallFunc actionWithTarget:self selector:@selector(limpiarSeleccionadas)];
CCAction *d = [CCCallFunc actionWithTarget:self selector:@selector(endTurn)];
[[_arregloBolitas objectAtIndex:random] runAction:[CCSequence actions: a, b, c, d, nil]];

I don't have your environment, you may need to modify a bit. Thanks.