I have a sprite which will 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.
+2
A:
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
OscarMk
2010-01-21 19:19:48
Thanx a lot oscar
Muniraj
2010-01-22 04:59:04