캔버스를 사용하여 지뢰 찾기 게임을 만드는 방법에 대한 안내에 따라 Javascript를 배우려고합니다. 옵션 막대를 클릭하면 캔버스에서 클릭으로 등록됩니다. This is a screenshot of the whole game so far. 캔버스를 계속 클릭 할 수 있지만 원하는대로 작동하지만 옵션 막대 (웃는 얼굴이있는 부분)를 클릭하면 캔버스에 클릭으로 등록되고 타일 중 하나가 제거됩니다. '때문에 할 수있는, 누군가가 문제를 찾기위한잘못된 요소에서 주어진 좌표
if(e.offsetX) { //Get's mouse pos relative to the canvas pos
mouseX = e.offsetX;
mouseY = e.offsetY;
}
else if(e.layerX) {
mouseX = e.layerX;
mouseY = e.layerY;
}
//mouseX = e.pageX; //Gets mouse pos relatiove to page
//mouseY = e.pageY;
//console.log("Mouse Pos on screen (x, y) = " + mouseX + "," + mouseY);//Validate that the mouse position is being recorded.
//Algorithm to tell which cube the click was on.
if (Math.floor(mouseX/settings.width) < settings.columns && Math.floor(mouseY/settings.height) < settings.rows){
clickX = Math.floor(mouseX/settings.width);
clickY = Math.floor(mouseY/settings.height);
console.log("Coords of clicked box (x,y)" + clickX + "," + clickY);
}
`
는 희망이 충분하다'
: 여기
는 마우스 클릭을 등록하는 코드입니다 티.
codepen 또는 jsfiddle에 가지고있는 것을 넣을 수 있습니까? 그런 식으로 문제를 이해하는 것이 훨씬 쉽습니다. – amadan
@amadan http://codepen.io/LeBarryScott/pen/ZBErWp?editors=1010 –