开发者

How do I animate a sprite using cocos2d?

开发者 https://www.devze.com 2022-12-18 03:30 出处:网络
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.

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

精彩评论

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