Cocos2dx v3 actionWithDuration

Hello folks!

I’m wondering whats the best way to port this part of code in cocos2dx 3.4:

float duration = 0.5f;			
CCSpawn *keyframeAction = [CCSpawn actionWithDuration:duration];

//some unimportant code here

CCMoveTo *moveAction = [CCMoveTo actionWithDuration:duration position:ccp(200,200)];
keyframeAction = [CCSpawn actionOne:keyframeAction two:moveAction];

Is it okay if I just do something like this:

float duration = 0.5f;
Spawn* keyframeAction;

//some code

MoveTo *moveAction = MoveTo::create(duration, Point(200, 200));
keyframeAction = Spawn::create(moveAction, NULL); 

?
Because I think this works a bit wrong and I dont know whats the problem at the moment. There is also no method actionWithDuration in cocos2dx 3.4. Any ideas? :open_mouth:

Hello,

The porting what you have done is correct. But Spawn is used when two action need to run at the same time. Here i can see only one action.
What is the use of using Spawn?
Can you explain it bit more?

Regards
Deepthi

@deepthi
Because as You can see in the original code the keyframeAction is created with duration:

CCSpawn *keyframeAction = [CCSpawn actionWithDuration:duration];

and in the ported code I dont have the first action “actionWithDuration” therefore I think thats a bit wrong… The porting is done a bit wrong… Can You take a closer look at it?

Bump! Anyone?

Hi Lem,

As Deepthi told Spawn is used when two action need to run at the same time.
In your case keyframeaction has only one action i.e duration. As per my knowledge syntax what you have written is wrong. If you are using Spawn then two action should be present.
Am not getting what exactly you want to do?

If you want create action with delay i.e in your case after some delay move action should perform then you can use Delay function.

auto* delayAction = DelayTime::create(duration); //Duration may be 6 or anything

Regards