4

我的游戏中有一个CCSprite,代表一个鸡蛋。我该如何摇晃它?我尝试了以下方法,但没有成功:

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]]];
4

4 回答 4

4

我在这里找到了一个非常适合 cocos2d-x 的奶昔。这是一个动作,可以与runAction

http://www.frozax.com/blog/2012/02/how-to-create-shake-action-cocos2d-x-source-code/

另一个摇动动作可以在 cocos2d 论坛上找到:

http://www.cocos2d-iphone.org/forum/topic/20327

于 2012-08-13T15:22:59.390 回答
3
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]];

这会给你缓和的效果。

于 2012-08-13T07:12:46.423 回答
2

嘿,我用下面的代码完成了它:

eggPlay.anchorPoint =  ccp(0.5,0.1);
 id rotateleft = [CCRotateBy actionWithDuration:0.5 angle:-10];
          id rotateright = [CCRotateBy actionWithDuration:0.5 angle:10];
        [eggPlay runAction:[CCRepeatForever actionWithAction:[CCSequence actions:rotateleft,rotateright,nil]]];
于 2012-08-13T09:02:56.537 回答
1

只需将它们左右移动,如下所示:

id menuItem1ActRight= [CCMoveBy actionWithDuration:1.5 position:ccp(-7,0)];
id menuItem1ActLeft= [CCMoveBy actionWithDuration:1.5 position:ccp(7,0)];
于 2012-08-13T07:37:48.793 回答