Cocos2d Jump Animation & Moving

依然范特西╮ 提交于 2019-12-25 03:19:14

问题


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.


回答1:


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



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


来源:https://stackoverflow.com/questions/18863121/cocos2d-jump-animation-moving

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!