Ajouter le touch sur mobile

This commit is contained in:
François Pelletier 2024-09-01 00:28:50 -04:00
parent e369061a9a
commit bbeec79627

View file

@ -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;
}