admin管理员组文章数量:1307752
I am drawing different shapes like rectangle, triangle, hexagon etc. using the canvas and 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 I clicked has this color but I don't want to use fill color method. Is there any other way to do it?
Also found isPointInPath but it did not work.
I am drawing different shapes like rectangle, triangle, hexagon etc. using the canvas and 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 I clicked has this color but I don't want to use fill color method. Is there any other way to do it?
Also found isPointInPath but it did not work.
Share Improve this question edited Aug 23, 2017 at 4:12 Flip 6,7818 gold badges50 silver badges83 bronze badges asked Feb 12, 2013 at 11:12 SandySandy 14.1k22 gold badges79 silver badges111 bronze badges2 Answers
Reset to default 2Check in here:
Javascript check Mouse clicked inside the Circle or Polygon
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
You could either try some canvas frameworks like http://kineticjs./ (check events section) which support already clickable elements out of the box or you'll need to write two functions, one which gives you your relative mouse click coordinates inside the canvas element (I used the one described here: https://stackoverflow./a/5932203/532102) and after write another function which checks if the returned mouse coordinates intersect with your shape on the canvas.
本文标签: javascriptHow to detect if a shape was clicked (HTML5 canvas)Stack Overflow
版权声明:本文标题:javascript - How to detect if a shape was clicked (HTML5 canvas)? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741811384a2398816.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论