I have a CCSprite
in my game, representing an egg. How do I go about shaking it? I tried the following, but without success:
id Runleft = [CCMoveTo actionWithDuration:0.1 position:ccp(244, 156)];
id RunRight = [CCMoveTo actionWithDuration:0.1 position:ccp(236, 156)];
[eggPlay runAction:[CCRepeatForever actionWithAction:[CCSequence actions:Runleft,RunRight,nil]]];
I found a really nice shake for cocos2d-x here. It's a action and can be used with runAction
http://www.frozax.com/blog/2012/02/how-to-create-shake-action-cocos2d-x-source-code/
another shake action can be found on the cocos2d forums:
http://www.cocos2d-iphone.org/forum/topic/20327
id menuItem1ActDown= [CCMoveBy actionWithDuration:1.5 position:ccp(0,-5)];
id menuItem1ActUp= [CCMoveBy actionWithDuration:1.5 position:ccp(0,+5)];
id menuItem1easeDown = [CCEaseInOut actionWithAction:menuItem1ActDown rate:2];
id menuItem1easeUp = [CCEaseInOut actionWithAction:menuItem1ActUp rate:2];
id seq1 = [CCSequence actionOne:menuItem1easeDown two:menuItem1easeUp];
[eggPlay runAction:[CCRepeatForever actionWithAction:seq1]];
This will give you easing effect.
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