![]() |
clickable grid on top of canvas
Ok, so lets say I'm trying to make a game that can be played on phone or computer. To do this I'm just going to use mousedown.
I'm creating a canvas, and then a <div> tag that will act as a grid over the canvas. I create an array like so, var grid = [ '0000', '0000', '0000' ]; Now I programed the grid array to populate in the div tag sitting on top of the canvas. What happens on the canvas depends on which grid box is clicked. How can I detect which grid box is clicked? I know it's probably using "this" but I seem to have trouble using that. I DON'T WANT A JQUERY SOLUTION. After I do that, how can i find the position that that specific grid box is in? meaning the css left and top. thanks |
I understand everything said and asked except what the meaning of your grid array is.
Is that supposed to mean that the overlay <div> is divided into 3 rows of 4 columns each? If so, are you wanting the JS code to automatically calculate the size of each cell in the grid? |
Quote:
|
Ummm...you only mentioned *ONE* <div>.
Quote:
Then what in the heck was the purpose of showing that useless dummy array??? If I think too literally, you write too irrelevant? Not hard, but if you want to worry about older MSIE you have to write one very tiny line of conditional code. Code:
<!DOCTYPE html> |
p.s.: You could instead use the computedStyle (again, you have to write browser-dependent code) to get the top left corner of the <div>. Google for "computedStyle" if you care.
|
Sorry Old, no one is quite as smart as you, that's why we are here. fyi, i wanted the array to build tiles of dives which would be clickable. duh
|
Quote:
Quote:
We can do that, still, if that's what you would prefer. Not hard at all. |
Hmmm, for a master coder you're not good at helping. Again, not everyone is as experienced as you are, and does not know the best solution to things, that is why we come here. Not to be talked down to. Thanks :)
|
I give up. I *WAS* just trying to find out what you were after. Trying to give you an answer to fit your needs. I gave you one answer but it didn't seem to be what you wanted. So I tried again. But I *still* don't know what you were asking for.
If it is "talking down to" to ask for more information, then I won't do so with you any more. I just won't talk to you and that will solve everything. |
An exemple with a grid
With a table. It's easy to find the clicked cells and ids which can give row and column.
See this grid Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
Quote:
|
| All times are GMT +1. The time now is 05:22 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.