10

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

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Sri
  • 827
  • 8
  • 34

2 Answers2

3

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

Karlth
  • 3,267
  • 2
  • 27
  • 28
  • am used cocos2d library only. here after how to do with box 2d physics library? alraedy it's completion stage. so you tel how to do this process in cocos2d without box2d physics library – Sri Jan 08 '11 at 05:45
  • 1
    Even though your code is complete I think it would be easier to add the Box2d library instead of implementing your own routines. http://blog.zincroe.com/2009/05/how-to-add-box2d-to-an-iphone-xcode-project/ – Karlth Jan 10 '11 at 13:06
1

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

tobiasbayer
  • 10,269
  • 4
  • 46
  • 64
Andrew
  • 24,218
  • 13
  • 61
  • 90