I'm detecting collisions in my game using sprite.boundingBox. It worked fine for me until I introduced a (car wheel) as another sprite that collides with other sprites as well. Clearly the wheel's boundingBox is not a rect and that's why it cannot detect intersections with other rects (collisions). Any help on how to detect the collision between the wheel and the other sprites?
Asked
Active
Viewed 49 times
1 Answers
0
A boundingBox as the name implies is always a rect which binds your sprite on all four sides.
If rectangle collision detection is all that you require for your game, then you can use the method that you have been using so far and it should work.

Abhineet Prasad
- 1,271
- 2
- 11
- 14
-
LOL. With all due respect, i'm asking about a way to detect collision between the wheel and other sprites. Clearly as stated before, cgrectintersectsrect didn't work when I tried it with the wheel. If it has been working out for me, i wouldn't have asked the question in the first place – Abdelrahman Salah Sep 27 '13 at 14:33
-
can you post some code so we can attempt at finding out why its not working for you? – Abhineet Prasad Sep 27 '13 at 14:34
-
If a boundingBox binds a sprite on all four sides, then what binds a circle to its perimeter? – Abdelrahman Salah Sep 27 '13 at 14:35
-
bounding Box is a term given to a hypothetical box which would just surround an object, in your case circle. i hope its clear now? – Abhineet Prasad Sep 27 '13 at 14:36
-
for (monster in monsters) { if(CGRectIntersectsRect(ulti.boundingBox, monster.boundingBox)) { [ultiKill addObject:monster]; } } for (monster in ultiKill) { [monsters removeObject:monster]; [self removeChild:monster cleanup:YES]; } [ultiKill release]; ultiKill=nil; [ultiKill dealloc]; – Abdelrahman Salah Sep 27 '13 at 14:36
-
I understand that. Cocos2d lets me use that boundingBox to detect collisions between two sprites. But if a circle is to collide with a rect, is there a method for example that analogical to CGRectIntersectsRect? lets say CGCircleIntersectsRect(sprite.boundingCircle,sprite2.boundingBox) – Abdelrahman Salah Sep 27 '13 at 14:40
-
i.e, if you are going to make a circle collide with another sprite, how would you do it? – Abdelrahman Salah Sep 27 '13 at 14:42
-
AFAIK cocos2d doesnt provide a CGCircleIntersectsRect function, but check out this question http://stackoverflow.com/questions/401847/circle-rectangle-collision-detection-intersection – Abhineet Prasad Sep 27 '13 at 14:44
-
also use, [monsters removeObjectsInArray:ultiKill] instead of the second loop. I guess that's your problem , cause you cant modify an NSMutableArray while iterating it. – Abhineet Prasad Sep 27 '13 at 14:46
-
put a CCLOG(@"the intersection condition was satisfied"); after you check for intersection and determine whether the condition is being satisfied or not. – Abhineet Prasad Sep 27 '13 at 14:47