Reputation: 12444
Is it possible to fade through the images in a CCSprite? Currently I only know its possible to fade through objects in Cocos2D but I wasn't sure if this was possible or not. Is there any way to do this?
Thanks!
Upvotes: 0
Views: 734
Reputation: 12446
You can fade with 2 CCSprites through multiple images.
Exchange the sprite:
CCCallBlock *exchangeImage = [CCCallBlock actionWithBlock:^{
sprite.texture = [[CCTextureCache sharedTextureCache] addImage:@"image.png"];
}];
Add delay if needed:
CCDelayTime *delayAction = [[CCDelayTime alloc] initWithDuration:0.4f];
Put together an repeat:
CCSequence *exchangeSequence = [CCSequence actions:exchangeImage, delayAction, nil];
CCRepeatForever *repeat = [CCRepeatForever actionWithAction:exchangeSequence];
[self runAction:repeat];
Upvotes: 0
Reputation: 18159
Well, you can use CCFadeOut
to remove your current image, while, at the same time, create your new sprite at the same position with opacity 0, and make it fade in with CCFadeIn
. If you do it at the same time, you should get a nice effect.
Upvotes: 3