0

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!

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Fdo
  • 1,053
  • 4
  • 15
  • 38
  • 1
    i see nothing wrong ... try the var_list constructor for the sequence, see if it changes the outcome. [CCActionSequence actions:a,b,c,d,nil]; – YvesLeBorg Oct 20 '14 at 01:00
  • Nope, couldn't find a difference using that constructor (besides the warning of the constructor taking CCActionFiniteTime instead of CCAction as parameters). Guess I'm gonna have to hack around this... I feel let down by cocos2d about the CCActionDelay not working, very important in games that rely on lots of action sequences (not this one thankfully, but for future projects it be a huge problem) :,( – Fdo Oct 20 '14 at 09:09
  • not certain, works for me every time, and i have lots of complex sequences. Dont feel let down, keep looking. – YvesLeBorg Oct 20 '14 at 11:28
  • 1
    i just coded your code 'as is' in one of my current project's launch screen, works as specified. I use 3.2.1. There is something else going on in your project that is causing this to fail. – YvesLeBorg Oct 20 '14 at 12:36
  • 1
    Yeah... I also posted this problem in spritebuilder forums, "hacked" around with a different aproach but still don't find the issue. Might look further into it later, cocos2d is amazing, I just had a micro-breakdown xD thanks for your help – Fdo Oct 20 '14 at 14:13
  • try to stop all actions on the random object before scheduling new actions. Who knows, you might be 'slamming' a new sequence on an object that is already busy implementing one. – YvesLeBorg Oct 20 '14 at 14:20

1 Answers1

0

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.

Jake Lin
  • 11,146
  • 6
  • 29
  • 40
  • I actually need 'c' to finish before 'd', not the other way around (and if they run at the same time, there is a chance of that happening)... Can you give me an example code of your suggestion regarding CCDelayTime? I thought CCActionDelay was the correct way to delay events in a CCActionSequence. – Fdo Oct 20 '14 at 00:35
  • you are mixing v2.x and v3.x syntax for cocos2d classes. – YvesLeBorg Oct 20 '14 at 01:01