I’m trying to make a fade in-fade out effect in cocos 2d, using a black png image. Its to make a better way to show something, instead of the casual way…
Is something wrong on this code?
- (void) effectFade {
CCSprite *effectScreen = [CCSprite spriteWithFile:@"black-iphone.png"];
effectScreen.opacity = 0;
[effectScreen runAction:[CCSequence actions:
[CCFadeIn actionWithDuration:1],
[CCCallFunc actionWithTarget:self selector:@selector(hideOutShowIn)],
[CCFadeOut actionWithDuration:1],
[CCCallFunc actionWithTarget:self selector:@selector(finish)],
nil]];
CCFadeTo *fadeIn = [CCFadeIn actionWithDuration:1];
CCFadeTo *fadeOut = [CCFadeOut actionWithDuration:1];
CCSequence *fadeSequence = [CCSequence actionOne:fadeIn two:fadeOut];
}
You don’t specify what is not working as expected, but it seems to me that you are not adding
effectScreento any layer or other node, so that it can be displayed.As to the rest, the code seems correct to me (aside from
fadeIn,fadeOut,fadeSequencethat are not used).EDIT:
you are definitely using
effectScreenin an ObjC/C sense; what you are not doing is adding it to your scene by doing something like:(assuming
selfis your scene or anotherCCNodeclass).The thing about not using
fadeSequenceis a bit different, since you are not using it in the ObjC/C sense: you define it and never ever reference it again.