Ajouter le touch sur mobile
This commit is contained in:
parent
e369061a9a
commit
bbeec79627
1 changed files with 7 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue