简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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