I want to get the lightning effect right for sprites in cocos2d. I know CCActions can help achieve the effect but How can I make an image appear for 0.2 seconds every 2 - 4 seconds?
Asked
Active
Viewed 189 times
0
-
Can you explain more on what you want to implement ?? you can use some images to explain ... or some demo code – shaqir saiyed Jul 23 '13 at 11:29
1 Answers
0
If by "lightning" you mean "blinking", you can do that by concatenating actions like this:
const ccTime shownInterval = 0.2;
const ccTime hiddenInterval = 2.0;
sprite.visible = NO;
[sprite runAction:
[CCRepeatForever actionWithAction:
[CCSequence actions:
[CCShow action],
[CCDelayTime actionWithDuration:shownInterval],
[CCHide action],
[CCDelayTime actionWithDuration:hiddenInterval],
nil]]];
From this, you can improve the visual effect by using CCFade
actions (which animate the opacity
property) instead of CCShow
and CCHide
actions (which operate on the visible
property).
I suggest you study the CCAction
class hierarchy to get a sense of which kind of actions does cocos2d make available.

Ricardo Sanchez-Saez
- 9,466
- 8
- 53
- 92