I am developing a game using COCOS2D. In my game, there are 4 points, each point is connected with each other by one line. When user moves the point, the lines move with the point. At the time of moving, if a line intersects with another line, line color should become red. How can I do this, i.e. line to colored red? And how to detect the intersection of two lines? Can anyone help me to solve this intersection problem in COCOS2D?
Asked
Active
Viewed 1,847 times
1
-
Please fix your formatting - you obviously speak decent English, so there is no excise for your spelling and gramatical abominations. – jrtc27 Nov 10 '11 at 07:13
-
@jrtc27: s/excise/excuse/ ;-P But I agree, a little bit more effort in providing a good question can be expected. – DarkDust Nov 10 '11 at 07:19
2 Answers
3
You can detect whether 2 segments intersect using this function provided by cocos2d.
BOOL ccpSegmentIntersect(CGPoint A, CGPoint B, CGPoint C, CGPoint D)

Luca Angeletti
- 58,465
- 13
- 121
- 148
1
There's a question that could be considered a duplicate of your question but it's more generic:
How do you detect where two line segments intersect?
It has a few nice algorithms, though the answer that might be the most useful for you is the answer from Gavin as it provides a C function that you can easily adapt.