Detecting collision with two or more shapes with Chipmunk
I wonder if anyone can suggest the best approach to detect c开发者_运维问答ollision 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
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.
精彩评论