Cocos2d fade in/out action to repeat forever
23,277
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];
}
Author by
Steve
Full time: husband, father and engineer. Part time: gardener, handyman, and now programmer. My iOS apps - PoolSnap (Pool chemistry assistant), Daybreak (Sunrise/set calculator)
Updated on February 26, 2020Comments
-
Steve about 4 years
I'm trying to make a method for my
CCSprite
basedPlayer
class to start the player instance fading in and out until stopped by callingstopAllActions.
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!
-
Steve almost 13 yearsI'm still gettting the incompatible pointer errors for both fade actions.
~/Player.m: warning: Semantic Issue: Incompatible pointer types sending 'CCAction *' to parameter of type 'CCFiniteTimeAction *'
-
Steve almost 13 yearsalthough if I change
CCAction
toCCFiniteTimeAction
the error goes away and it works... why would that be? -
Steinbitglis almost 13 yearsI understand now, you typecasted to CCAction when you didn't have to. CCFadeTo inherits CCFiniteTimeAction. That is all CCSequence needs to know. I edited my answer accordingly.
-
Steve almost 13 yearsThanks - works now too. One more thing... the opacity property should be set to 255 in the first line if I want it fully visible, right?
-
Steinbitglis almost 13 yearsYes, it's the equivalent of 0xff
-
Ankish Jain almost 10 yearsif for above pulse animation i want to increase or decrease animation speed dynamically on some action , how do to ?? Been searchin a lot , dint get an answer.got a deadline soon ! thnx
-
Ankish Jain almost 10 yearsHow do you change the duration of the above fade to dynamically?