Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

collision detection in cocos2d

i want to detect collision detection two times in same row.

for example:-(see the below image)

the ellipse and rectangle or detcted. after that my ellipse will travelling in the straight line path to down and detect the another rectangle.

first one is( travelled in trajectory path ) working fine. second one i want to pass in straight line to down for collision detection.

how to do this process.

alt text

like image 222
Sri Avatar asked Jan 06 '11 10:01

Sri


2 Answers

Use the Box2D physics library for collision detection. It is by far the best option in your case and elegantly supported in Cocos2d.

See here: http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone

like image 154
Karlth Avatar answered Oct 14 '22 22:10

Karlth


As i know cocos2d have no collision detection of sprites because it's not a phys engine. If you want the collision be detected automatically use Box2D or chipmunk physics engine, supported by cocos2d.

If the number of object you want to check for collision is small you can just run over your object and check if some of them (or only one if it's enough for you) overlaps with the others.

Making more complex collision detection will bring you for writing a collision detection part of a physics engine. It's much simpler to use en existing one

like image 43
Andrew Avatar answered Oct 14 '22 20:10

Andrew