From bbeec79627648eebe809d2715401645a55ec50af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pelletier?= Date: Sun, 1 Sep 2024 00:28:50 -0400 Subject: [PATCH] Ajouter le touch sur mobile --- public/javascripts/game.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/public/javascripts/game.js b/public/javascripts/game.js index f1c7dd4..09aa999 100644 --- a/public/javascripts/game.js +++ b/public/javascripts/game.js @@ -40,7 +40,13 @@ function drawBall() { function movePaddle(e) { if (!isPaused) { - let relativeX = e.clientX - canvas.offsetLeft; + let relativeX; + if (e.type.startsWith('mouse')) { + relativeX = e.clientX - canvas.offsetLeft; + } else if (e.type.startsWith('touch')) { + relativeX = e.touches[0].clientX - canvas.offsetLeft; + e.preventDefault(); // Prevent scrolling when touching the canvas + } if (relativeX > 0 && relativeX < canvas.width) { paddle.x = relativeX - paddle.width / 2; }