HTML 5 Canvas - Grid Block Fill

I created a canvas and wrote out a grid (similar to graphic paper) with the coordinates X and Y. Now I want to do the following:

-When someone clicks the mouse, the square in the grid will change to a different color
-When the block is selected, the data will not change.

+5
source share
1 answer

You need a separate 2D array that maintains state for each position (x, y) of the grid.

When a click occurs, check this state array to see if the cell has been clicked before, and refresh the canvas if necessary.

I created a small demo to show you: http://jsfiddle.net/alnitak/xN45K/

+6
source

All Articles