Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I recently needed to do the same, and didn't want to deal with pixel shaders. I figured I could mess with how the texture is blended into the scene to get some sort of white flash out of it.</p> <p>So, I figured out a reasonable light-flash effect by repeatedly changing the sprite's Destination glBlend function from GL_ONE_MINUS_SRC_ALPHA to GL_ONE, and then back.</p> <p>Here's my toggle method:</p> <pre><code>-(void)toggleBlendFlash { if (sprite_) { ccBlendFunc blendFunc = sprite_.blendFunc; if (blendFunc.dst == GL_ONE_MINUS_SRC_ALPHA) { blendFunc.dst = GL_ONE; //flash white } else { blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA; //default } sprite_.blendFunc = blendFunc; } } </code></pre> <p>Here's my flashing sequence:</p> <pre><code>CCSequence *sequence = [CCSequence actions: [CCCallFunc actionWithTarget:targetEnemy selector:@selector(toggleBlendFlash)], [CCDelayTime actionWithDuration:0.3], [CCCallFunc actionWithTarget:targetEnemy selector:@selector(toggleBlendFlash)], [CCDelayTime actionWithDuration:0.2], nil ]; </code></pre> <p>It may not look perfect for your situation, but give it a try! </p> <hr> <p>EDIT 1: Also, check these links out for more info/resources:</p> <ul> <li><a href="http://digitallybold.com/314/cocos2d-additive-sprite-color-tinting" rel="nofollow">http://digitallybold.com/314/cocos2d-additive-sprite-color-tinting</a> </li> <li><a href="http://www.andersriggelsen.dk/glblendfunc.php" rel="nofollow">http://www.andersriggelsen.dk/glblendfunc.php</a> </li> </ul> <p>EDIT 2: </p> <p>Of course, I just realized that if your sprite is animating between different CCTexture2D objects (e.g. you have 1 file per frame), then it resets your blendFunc for every frame, which means you have to either create a category or a subclass for CCSprite or CCAnimate to re-apply your custom blendFunc... so I guess its not as quick of a solution as I had originally thought.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload