我有一个精灵,它将向右,向左和向右移动。 我需要将动作添加到动画精灵,即动画精灵应跳,左右转。 任何人都可以告诉我如何使用示例代码。
答案 0 :(得分:5)
这里的cocos2d代码非常简单:
Sprite *mySprite = [Sprite spriteWithFile@"mySprite.png"];
[mySprite setPosition:ccp(x,y)];
[self addChild:mySprite]; //This displays the Sprite in your layer
现在你打算做的序列......
id moveRight = [MoveBy actionWithDuration:2 position ccp(x+k,y) //Where k is how much to the right you want it to go.
id moveLeft = [MoveBy actionWithDuration:2 position ccp(x-k,y)];
id jump = [JumpBy actionWithDuration:1 position:ccp (x,y) height:1 jumps:1];
id sequence = [Sequence actions:moveRight,moveLeft,jump,nil];
[mySprite runAction:sequence];
希望这很清楚。
-Oscar