最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - HTML 5 Canvas - Grid Block Fill-In - Stack Overflow

programmeradmin0浏览0评论

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/

发布评论

评论列表(0)

  1. 暂无评论