Reputation: 53
How do I start to implement a class for sprite collision?
Upvotes: 4
Views: 12254
Reputation: 6934
I would look into b2ContactListener
You can do some searches on that, and you'll easily get some results
Upvotes: 2
Reputation: 64477
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?
Upvotes: 6
Reputation: 865
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]
Upvotes: 1
Reputation: 14084
You want to use the chipmunk's physics engine, which is part of the cocos2d engine.
Upvotes: 0