简体   繁体   English

使画布区域成为对象

[英]Make canvas area into an object

Is there a way, without external libraries, to make a specific area of a canvas into an independent object. 没有外部库,有没有一种方法可以将画布的特定区域变成独立的对象。 For example on a canvas you take a 50 by 40 rectangle and make it have events independent from the whole canvas. 例如,在画布上,您采用50 x 40的矩形,并使它具有独立于整个画布的事件。

No, the canvas is just pixels and the shapes drawn on the canvas are not "remembered". 不,画布只是像素,并且不会“记住”在画布上绘制的形状。

What you need to do is listen for events on the canvas and then test if the mouse event occurred over the rectangle you're interested in by comparing the mouse coordinates with the X/Y, Width/Height of that rectangle. 您需要做的是侦听画布上的事件,然后通过将鼠标坐标与该矩形的X / Y,宽度/高度进行比较,来测试鼠标事件是否发生在您感兴趣的矩形上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM