admin管理员组

文章数量:1431034

I've created a Canvas and have written out a grid(resembles graph paper) with the X & Y coordinates successfully. What I'm looking to do now is the following:

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

I've created a Canvas and have written out a grid(resembles graph paper) with the X & Y coordinates successfully. What I'm looking to do now is the following:

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

Share Improve this question asked May 12, 2012 at 15:31 Matthew LancasterMatthew Lancaster 5193 gold badges12 silver badges22 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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

When a click happens, check that state array to see if the cell was clicked before, and update the canvas as appropriate.

I created a little demo to show you: http://jsfiddle/alnitak/xN45K/

本文标签: javascriptHTML 5 CanvasGrid Block FillInStack Overflow