开发者

How do I animate a sprite using cocos2d?

I have a sprite which w开发者_如何学Goill move right,left and jump. I need to add the action to a animated sprite ie an animated sprite should jump, turn right and left. Can anyone please tell me how to do it with sample code.


This is quite simple with cocos2d code here:

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

Now for the sequence you intend to do...

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

Hope that's clear.

-Oscar

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜