Hi All,
May be some one has had similar experiences on this dilemma and can help me out here...
Basically, I have a canvas element on which I draw several rectangles in a loop using
context.fillRect (x, y, width, height)
Now, I want some of the rectangles to be hotspots and respond to click events. I can find out the exact (x,y) of a click event using event.layerX
and event.layerY
.
Given that I know the following:
- the exact x,y of the click
- the x,y,width and height of every rectangle
how do I find out if the click event occurred inside the perimeter a certain rectangle or not?
and,
which rectangle the click event occurred 0n?
Is there like a mathematical formula for this?
Any help would be much appreciated, and if I'm not clear enough, let me know...
Thanks
EDIT
Is there no better way than to loop through all rectangles and check their position and dimensions?