Swift Cocos2d3.x CCSprite applyImpulse not giving proper jump

坚强是说给别人听的谎言 提交于 2019-12-25 06:56:23

问题


I am using Cocos2d3.x with SpriteBuilder in Swift language.

I want to make some animation like bouncing ball on Polls as seen in this GIF: https://www.dropbox.com/s/43vwlbjoazaxe7u/jumpyBall_15_jul_15.gif?dl=0

If you have noticed in the GIF file, each second jump is half of the previous jump. So, it seems pattern of 1,0.5,1,0.5,1,0.5,...

Following are my settings:

Polls:

Physics Enabled
Density: 1.0
Static Body
Collision Type: Platform

Circle:

Physics Enabled
Density: 1.0
Dynamic Body
Collision: hero
Affected by gravity

MainScene:

func ccPhysicsCollisionBegin(pair: CCPhysicsCollisionPair!, hero: Player!, platform: Obstacle!) -> Bool {
    hero.physicsBody.applyImpulse(ccp(0, distanceObst));
}

distanceObst is the distance between polls which is 160.

Can someone give me suggestions over what I should do to make jumps uniform for each bounce? And I as well want to speed up player jumps, so is there any simplest way or formula or something?

来源:https://stackoverflow.com/questions/31492803/swift-cocos2d3-x-ccsprite-applyimpulse-not-giving-proper-jump

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