开发者

Objective C - Quartz 2D finding line intersect

I'm currently using CGContextMoveToPoint, CGContextAddLineToPoint & CGContextStrokePath to draw lines on a view.

Basically making a snake game that also allows user to move diagonally.

Is there a way to find when 2 lines that I dr开发者_如何学运维aw intersect or do I have to manually calculate each lines and see if anything intersects?

Thanks,

Tee


Since the CG methods are somewhat CPU heavy, your best bet is to write a method that calculates an intersection point using basic geometry. Or use the Sweep Line algorithm, it shouldn't be too hard.

EDIT: In fact, since you're making a snake game wherein blocks are laid out in a grid, you can just flag some of the blocks as containing a snake/whatever and if a block is about to be flagged twice, then you do whatever you wanted to do upon line intersection.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜