我的游戏中有一个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]]];
答案 0 :(得分:4)
我在这里找到了一个非常好的cocos2d-x摇晃。这是一个动作,可以与runAction
http://www.frozax.com/blog/2012/02/how-to-create-shake-action-cocos2d-x-source-code/
可以在cocos2d论坛上找到另一个动作:
答案 1 :(得分: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]];
这会给你缓和效果。
答案 2 :(得分: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]]];
答案 3 :(得分:1)
只需按下方左右移动它们:
id menuItem1ActRight= [CCMoveBy actionWithDuration:1.5 position:ccp(-7,0)];
id menuItem1ActLeft= [CCMoveBy actionWithDuration:1.5 position:ccp(7,0)];