Intersection Between 2 lines in COCOS2D

泄露秘密 提交于 2020-01-16 00:52:05

问题


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?


回答1:


You can detect whether 2 segments intersect using this function provided by cocos2d.

BOOL ccpSegmentIntersect(CGPoint A, CGPoint B, CGPoint C, CGPoint D)




回答2:


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.



来源:https://stackoverflow.com/questions/8076036/intersection-between-2-lines-in-cocos2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!