So far I am able to control my sprite's side to side movement with buttons in Cocos2d. I am now trying to incorporate a jump animation but I have absolutely no idea how to do this. I have tried one sample code which utilized the init method and combined to animations (jump up and jump down) but whenever I tried to move the sprite while it was jumping i got a SIGABRT error. Please note that I am very unexperienced with Cocos2d and walking me through the steps to make a successful jump animation would be greatly appreciated.
Asked
Active
Viewed 2,665 times
0
-
To get jump action , what have you used? Did you use any action?? Like CCJump? – Renaissance Sep 18 '13 at 05:07
-
You can get Jump Effect using CCJumpTo or CCJumpBy action. – Renaissance Sep 18 '13 at 05:07
-
@Renaissance This was my exact code: `id jump_Up = [CCJumpBy actionWithDuration:1.0f position:ccp(0, 200) height:50 jumps:1]; id jump_Down = [CCJumpBy actionWithDuration:0.7f position:ccp(0,-200) height:50 jumps:1]; id seq = [CCSequence actions:jump_Up,jump_Down, nil]; [sprite runAction:seq];` – CompleteXcodeNoob Sep 18 '13 at 11:45
-
@Renaissance That code only allowed me to jump up and down without detecting hitting the ground or any other objects. It was a set animation that did't allow me to make the sprite move right or left or allow me to jump relative to the ground (which i haven't figured out how to do either). – CompleteXcodeNoob Sep 18 '13 at 11:48
-
code which you have given, in that the sprite will come back to its position with 1.7 seconds. – Renaissance Sep 18 '13 at 12:00
-
I am not getting what you want to do. If you can edit your question and add some demo images of your problem than it is easier to guide you. – Renaissance Sep 18 '13 at 12:01
-
@Renaissance This code is fine for just jumping up and down but it won't allow my sprite to do other animations such as moving side to side while it is active. I want the sprite to jump and when it comes down to be relative to the x axis. – CompleteXcodeNoob Sep 18 '13 at 20:01
-
ohh...so you have to keep record of actions of your sprite, So when your sprite finish that action at that time you have to move your sprite side by side.For moving sprite side by side you have to use CCMoveTo action. – Renaissance Sep 19 '13 at 04:50
2 Answers
3
CCJumpBy simulates a parabolic jump movement.
id jump_Up = [CCJumpBy actionWithDuration:1.0f position:ccp(0, 200) height:50 jumps:1];
Running the above jump_Up action will move the sprite's position by '0' distance along x axis and '200'units along y axis and will move the sprite along a parabolic path.
If you wish to move the sprite right or left while jumping. Try the following..
CGPoint newPosition = ccp(max(sprite.position.x + screenSize.width * 0.2f,screenSize.width), sprite.position.y);
id jumpAct = [CCJumpBy actionWithDuration:1.0f position:newPosition height:50 jumps:1];
[sprite runAction:jumpAct];

Abhineet Prasad
- 1,271
- 2
- 11
- 14
-
-
@Pizzy213codes i'm sorry.. didn't get that..you really want to make your what? – Abhineet Prasad Mar 22 '14 at 09:37
2
Just a quick update - with the V3 release of Cocos2D, the method is now CCActionJumpBy. So it's something like this...
CCActionJumpBy *jump = [CCActionJumpBy actionWithDuration:1.0f position:ccp(0, 200) height:50 jumps:1];
[_yourSpriteObject runAction:jump];

Jon K
- 160
- 1
- 13