I have a HTML5 canvas on which I have drawn several shapes.
What I want to happen, is that when the mouse is clicked on any shape the shape should get selected (at least it can tell what kind of shape is selected).
Thank you.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try using an existing canvas library (or create your own) that has an event when a shape is being selected.
The example below uses the Kinetic JS library, and the example below is from HTML5 Canvas Region Events Example:
In addition, I have included some mouse-in detection if the cursor is within the shape, without using any javascript libraries.
Rectangular-based mouse-in detection:
Circle-based mouse-in detection: