Reputation: 75
I'm working on a game and I need to detect collisions between a line and a polygon. After much googling, it seems that cocos2d does not support polygon collisions?
I'm able to perform line and rect collision detection, but not polygon. Do I have to move to Box2d? Any advice is much appreciated.
Upvotes: 0
Views: 1998
Reputation: 34017
cocos2d
offers just simple collision detection like CCRect::rectContainsPoint
(in cocos2d-x
) or rectIntersectsRect
.
If your polygon is a rectangle then you could make the detection by judging if there is a point of the line contained by that rectangle.
Upvotes: 0
Reputation: 64477
Cocos2D doesn't offer any kind of collision detection. What you want is a ray vs polygon intersection test, that's something you can do with Box2D or Chipmunk. Both are included in Cocos2D (for iPhone). Box2D and Chipmunk allow for implementation of the game physics like gravity, wind, collision detection etc.
If you require to do a 'sort of' detection in plain Cocos2D then I recommend the use of CGRectContainsCGRect or CGRectContainsCGPoint or CGRectIntersectsCGRrect functions to do the same. This may help you achieve what you want but it won't be as nice as the use of Box2D or Chipmunk game physics.
Upvotes: 1