I want to have a sprite scale up and down once every second to make it seem like it is bulging and pulsating. How can I do this?
As the post before contains syntax errors. To be more precise, I post working code:
CCSprite * sprite = ...; // create the sprite.
id scaleUpAction = [CCEaseInOut actionWithAction:[CCScaleTo actionWithDuration:1 scaleX:1.0 scaleY:1.0] rate:2.0];
id scaleDownAction = [CCEaseInOut actionWithAction:[CCScaleTo actionWithDuration:0.5 scaleX:0.8 scaleY:0.8] rate:2.0];
CCSequence *scaleSeq = [CCSequence actions:scaleUpAction, scaleDownAction, nil];
[sprite runAction:[CCRepeatForever actionWithAction:scaleSeq]];
You could use a simple [CCScaleTo ..] action or if you want to create your own "effect" you could advance the CCFiniteTimeAction. I would prefer the first one :
CCSprite * sprite = ...; // create the sprite.
sprite.anchorPoint = ccp( 0.5, 0.5 ); center the pivot
id myAction = [CCRepeatForEver actionWithActions:[CCScaleTo actionWithDuration:0.5 scaleX:2.0 ScaleY:2.0],[CCScaleTo actionWithDuration:0.5 scaleX:0.5 ScaleY:0.5], nil];
[sprite runAction:myAction];
use CCEase to make the animation nonlinear
id myAction = [CCRepeatForEver actionWithActions:[CCEaseInOut actionWithAction:[CCScaleTo actionWithDuration:0.5 scaleX:2.0 ScaleY:2.0] rate:2.0],[CCEaseInOut actionWithAction:[CCScaleTo actionWithDuration:0.5 scaleX:0.5 ScaleY:0.5] rate:2.0], nil];
this post may contain errors. but I hope you understand the way to come to the goal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With