← Back to home

cocos2d Tip: Opacity, CCFadeOut, & CCFadeTo

August 12, 2010

When using opacity and want to fade out, use fade to!

Using fade out it will reset the opacity and then fade it out... so a fade to opacity 0, will prevent the reset.

// GIVEN
CCSprite *sprite = [CCSprite spriteWithFile:@"sprite"];
sprite.opacity = 150;

// DO
[sprite runAction:[CCFadeTo actionWithDuration:1.0f opacity:0]];

// DON'T
[sprite runAction:[CCFadeOut actionWithDuration:1.0f]];

← Back to home