From 3742ceafff80b24ce53ce30bd7aaa00729215da0 Mon Sep 17 00:00:00 2001 From: Marcel Date: Thu, 10 May 2018 14:36:43 +0200 Subject: [PATCH] Fix clicking position --- minesweeper.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/minesweeper.js b/minesweeper.js index 8c338e9..dba2a19 100644 --- a/minesweeper.js +++ b/minesweeper.js @@ -267,8 +267,8 @@ function gameOverEvent() { } function getPosition(e) { - const x = (e.x - canvas.offsetLeft) / W * zoomFactor + windowX; - const y = (e.y - canvas.offsetTop) / H * zoomFactor + windowY; + const x = (e.x - (window.innerWidth - W) / 2) / W * zoomFactor + windowX; + const y = (e.y - (window.innerHeight - H) / 2) / H * zoomFactor + windowY; const fieldX = Math.floor(x * fieldSize.x); const fieldY = Math.floor(y * fieldSize.y);