html5 canvas检测是否单击内部形状 [英] html5 canvas detect if clicked inside shape
问题描述
我绘制不同的形状,如矩形,三角形,六边形等使用canvas lineTo方法像 此博客 。我只想要一个简单的方法来找到如果我点击一个形状。我可以通过填充一些颜色的形状,并检查点,我点击的点有颜色,但我不想使用填充颜色方法。还有其他方法吗?
I am drawing different shapes like rectangle, triangle, hexagon etc. using canvas lineTo method like in this blog. I just want a simple way to find if I clicked inside a shape. I can do it by filling the shape with some color and the checking if the point where I clicked have color but I don't want to use fill color method. Is there any other way to do it?
也找到 isPointInPath ,但它无效。
Also found isPointInPath but it did not worked.
推荐答案
请在此处查看:
meouw 答案肯定我已经测试,并保证它的工作原理。
似乎还有一些其他解决方案,也被upvoted,
也许你可以尝试他们,
meouw answer works for sure I've test it and guarantee it works. It seems that there are some other solutions, too that have been upvoted, maybe you can try them, either
这篇关于html5 canvas检测是否单击内部形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!