Swift Cocos2d3.x CCSprite applyImpulse not giving

2019-09-01 17:27发布

问题:

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?