Repeat CCAction Certain Number of Times?
-
07-07-2021 - |
Question
In Cocos2D 2.x, I am doing runAction to do some animations in my game. It is working great but I want the animation to repeat a certain number of times.
So pretty much my pseudo-code is this:
CCSequence... action1, action2
[sprite runAction:theSequence];
So I just want to repeat the action for (lets say 3 times), how would I do this? I do not see any API to do this but maybe I am just not seeing something. If anyone knows how to do this and could share the information that would be great!
Thanks!
Solution
You can use CCRepeat to repeat an action a number of times:
id repeatAction = [CCRepeat actionWithAction:theSequence times:3];
[sprite runAction:repeatAction];
OTHER TIPS
$$ You can use CCRepeatForever to Repeat action: $$
id scaleAction = [CCEaseInOut actionWithAction:[CCScaleTo actionWithDuration:3.0f scaleX:1.0 scaleY:1.0] rate:2.0];
id scaleUpAction = [CCEaseInOut actionWithAction:[CCScaleTo actionWithDuration:1.0f scaleX:4.8 scaleY:4.8] rate:2.0];
id scaleUpAction1 = [CCEaseInOut actionWithAction:[CCScaleTo actionWithDuration:12 scaleX:4.8 scaleY:4.8] rate:2.0];
CCSequence *scaleSeq = [CCSequence actions:scaleAction,scaleUpAction,scaleUpAction1, nil];
[scaleleft runAction:[CCRepeatForever actionWithAction:scaleSeq]];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow