Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocos2d fade in/out action to repeat forever

I'm trying to make a method for my CCSprite based Player class to start the player instance fading in and out until stopped by calling stopAllActions.

In my Player class I have:

- (void)pulse
{
    [self setOpacity:1.0];
    CCAction *fadeIn = [CCFadeTo actionWithDuration:0.5 opacity:0.5];
    CCAction *fadeOut = [CCFadeTo actionWithDuration:0.5 opacity:1.0];

    CCSequence *pulseSequence = [CCSequence actions:
                                 fadeIn, // I get a warning about incompatible pointer types...
                                 fadeOut, 
                                 nil];
    [self runAction:pulseSequence];
}

This doesn't work and doesn't address the repeat forever part. I know I should probably use CCRepeatForever but I'm not seeing how to implement it correctly.

Thanks!

like image 681
Steve Avatar asked May 29 '11 20:05

Steve


1 Answers

I have not run this, but I think others have succeeded with something like:

- (void)pulse
{
    [self setOpacity:1.0];
    CCFadeTo *fadeIn = [CCFadeTo actionWithDuration:0.5 opacity:127];
    CCFadeTo *fadeOut = [CCFadeTo actionWithDuration:0.5 opacity:255];

    CCSequence *pulseSequence = [CCSequence actionOne:fadeIn two:fadeOut];
    CCRepeatForever *repeat = [CCRepeatForever actionWithAction:pulseSequence];
    [self runAction:repeat];
}
like image 120
Steinbitglis Avatar answered Oct 15 '22 03:10

Steinbitglis