Say we drawed multiple rectangles in a html5 canvas:
context.fillStyle='black';
context.fillStroke='black';
context.beginPath();
for(var i=0; i<50; i++)
{
context.rect(i*20,i*20,w,h);
//this is just some random configuration for the rectangles, it doesn't really matter how they are positioned
}
context.closePath();
context.fill();
context.stroke();
How can I make it so it's recognizable when the user click on an individual rectangle and then, say, change it's color?
Is it possible or will I have to make a function that takes the mouse x and y coordinates and then check where it landed compared to the x and y coordinates of the rectangles, to finally find the one that "covers" the mouse coordinates?