问题
How do I start to implement a class for sprite collision?
回答1:
As Eric pointed out, CGRectIntersectsRect is the method to test two bounding rects for overlapping. Use the boundingBox method of the CCNode classes to get the correct bounding box for each sprite (or other node).
See my answer here: Collision Detection in Cocos2d game?
回答2:
I would look into b2ContactListener
You can do some searches on that, and you'll easily get some results
回答3:
You can also perform very simple collision detecting by checking if two rectangles intersect. You can use the CGRectIntersectsRect function to do this. Basically, both rects are based on the position and dimensions of sprites you want to check for collisions. If CGRectIntersectsRect returns true, you know a collision occurred.
More info here: [http://icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/][1]
回答4:
You want to use the chipmunk's physics engine, which is part of the cocos2d engine.
Example (iPhone)
来源:https://stackoverflow.com/questions/1338569/how-can-i-test-sprite-collision-in-cocos2d