vendredi 31 octobre 2014

How could a log X, Y mouse position on my grid?


Vote count:

0




I have this script to create grid of rectangles, how would I go about logging map co ordinates of the mouse position so if the mouse was on 1,1 it would log 1,1?:



0,0|0,1|0,2|0,3
1,0|1,1|1,2|1,3
2,0|2,1|2,2|2,3
3,0|3,1|3,2|3,3


here is the script I have to create the grid;



var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
canvas.width = (32 * 12);
canvas.height = (32 * 12);
document.body.appendChild(canvas);

var posX = 0;
var posY = 0;
var tileSize = 32;

$(document).ready(function(){
drawGrid();
});

function drawGrid(){
for(var x = 0; x < 12; x++){
for(var y = 0; y < 12; y++){
ctx.rect(posX, posY, tileSize, tileSize);
ctx.stroke();
posX += tileSize;
}
posY += tileSize;
posX = 0;
}
}


asked 43 secs ago







How could a log X, Y mouse position on my grid?

Aucun commentaire:

Enregistrer un commentaire