giorashc
giorashc

Reputation: 13713

Preventing jump more than once

I am writing an iphone game using cocos2d and box2d engines. I have a ball which can be jumped by tapping the screen. The jump is applied by using ApplyImpulse method on the ball's body.

Thing is I do not want the ball to jump more than once. (i.e. If the ball is in mid-air I do not want it to be jumped again when tapping the screen.)

Is there a way to know when an object is in mid-air ? Is there a common solution to this problem ?

Thanks

Upvotes: 0

Views: 152

Answers (1)

Rui Campos
Rui Campos

Reputation: 453

You can raycast from the center of the ball, downwards. If it collides with anything at a distance greater than the ball's radius, that means it is in the air.

To raycast, check chapter 10 in the manual here: http://box2d.org/manual.pdf

It's in c++ but you should find similar examples in objective-c.

Hope it helps.

Upvotes: 2

Related Questions