如何检测是否单击了一个形状(HTML5画布)? [英] How to detect if a shape was clicked (HTML5 canvas)?

查看:116
本文介绍了如何检测是否单击了一个形状(HTML5画布)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用画布和<$ h $ => http://blog.riacode中的 lineTo 方法绘制不同的形状,如矩形,三角形,六边形等。 in / 2011/03/03 / drawing-regular-polygons-in-html5-canvas /rel =nofollow noreferrer> 此博客 。我想要一个简单的方法来查找我是否单击了一个形状。我可以通过用一些颜色填充形状来检查我点击的点是否有这种颜色,但我不想使用填充颜色方法。还有其他办法吗?

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?

还找到 isPointInPath 但它不起作用。

Also found isPointInPath but it did not work.

推荐答案

在此处办理登机手续:

Javascript检查鼠标在圆圈或多边形内部点击

meouw 回答肯定​​我已经测试过并确保它有效。
似乎还有一些其他的解决方案也被赞成,
也许你可以尝试一下,或者

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画布)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆