Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to shake CCsprite in cocos2d?

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]]];
like image 897
Nims Avatar asked Dec 27 '22 19:12

Nims


2 Answers

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

like image 60
zeiteisen Avatar answered Jan 17 '23 08:01

zeiteisen


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.

like image 28
stack Avatar answered Jan 17 '23 10:01

stack