0

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?

NSCodeman
  • 51
  • 4

1 Answers1

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