1

I wonder if anyone can suggest the best approach to detect collision between multiple shapes.

I am using Chipmunk on an iPad with iOS 4.2 and Cocos2D 1.0 - I basically have a cpShape travelling around the iPad screen - there are two segment cpShape's (arranged in a V-shape) and I'd like to know when my travelling shape is touching BOTH the segment shapes (ie the corresponding sprite is sitting comfortably inside the V).

Any ideas? I have set up my callback with cpSpaceAddCollisionHandler but I don't seem to have a list of all of the shapes the current colliding shape is touching. Is that possible or do I have to code and store the information manually?

Thanks

fedmest
  • 709
  • 5
  • 17

1 Answers1

0

i think your going to have to store some data in your sprite object.

There are callbacks in chipmunk for when 2 objects first touch, and then they part.

  • Begin: Two shapes just started touching for the first time this step. Return true from the callback to process the collision normally or false to cause Chipmunk to ignore the collision entirely. If you return false, the pre-solve and post-solve callbacks will never be run, but you will still recieve a separate event when the shapes stop overlapping.

  • Separate: Two shapes have just stopped touching for the first time this step.

You could make your object that is to 'sit within the V' have a 2 bool's one for each side of the V, make it true when they 'begin' and false when they separate.

If they are both true, and the object isSleeping (stop moving) (i come from a box2d background, not sure the chipmunk equivalent is).

Hope that helps.

Bongeh
  • 2,300
  • 2
  • 18
  • 30
  • It does help, thanks! I was thinking of something along the same lines, but wanted to get the opinion of someone with more experience than myself. Where would you store the two booleans? At the moment the data I set for the shapes is the actual sprites they are associated with. Would you just create an extra object that holds both the booleans and the sprite, and use that as the data, or would you have a better suggestion? Thx – fedmest May 12 '11 at 18:11
  • subclass CCSprite, give your new SpriteClass two boolean instance variables, this way you could have multiple sprites sitting in the v (if they didnt collide with each other), if you so desired. – Bongeh May 13 '11 at 12:06
  • good point, easier than having another data structure in my app, thanks! – fedmest May 16 '11 at 10:40