How can I test sprite collision in cocos2d?
Solution 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?
Solution 2
I would look into b2ContactListener
You can do some searches on that, and you'll easily get some results
Solution 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]
user162304
Updated on June 04, 2022Comments
-
user162304 almost 2 years
How do I start to implement a class for sprite collision?
-
LearnCocos2D over 13 yearsfor "simple" collision detection you don't need a physics engine, that's overkill.
-
Michael Wildermuth about 12 yearsI believe this is apart of box2d which is apart of Cocos2d. Might help with your searches.
-
Daniel Benedykt about 12 yearsbox2d is a physics engine. Can be too much for just collision detection