如何使用cocos2d为sprite设置动画?

0 iphone cocos2d-iphone

我有一个精灵,它将向右,向左和向右移动.我需要将动作添加到动画精灵,即动画精灵应跳,左右转.任何人都可以告诉我如何使用示例代码.

Osc*_*mez 5

这里的cocos2d代码非常简单:

Sprite *mySprite = [Sprite spriteWithFile@"mySprite.png"];
[mySprite setPosition:ccp(x,y)];
[self addChild:mySprite]; //This displays the Sprite in your layer
Run Code Online (Sandbox Code Playgroud)

现在你打算做的序列......

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];
Run Code Online (Sandbox Code Playgroud)

希望很清楚.

-Oscar