diff --git a/public/index.html b/public/index.html index ce52ef4..cf9cf63 100644 --- a/public/index.html +++ b/public/index.html @@ -103,17 +103,26 @@ currentX: 0, currentY: 0, lastCheckedX: 0, - lastCheckedY: 0 + lastCheckedY: 0, + shouldResetTouch: false, } touchpad.addEventListener("touchmove", (event) => { movementState.currentX = event.touches[0].clientX; movementState.currentY = event.touches[0].clientY; + if (movementState.shouldResetTouch) { + movementState.shouldResetTouch = false; + movementState.lastCheckedX = movementState.currentX; + movementState.lastCheckedY = movementState.currentY; + } const deltaX = movementState.currentX - movementState.lastCheckedX; const deltaY = movementState.currentY - movementState.lastCheckedY; movementState.lastCheckedX = movementState.currentX; movementState.lastCheckedY = movementState.currentY; connection.sendMessage("r", [deltaX, deltaY]); }); + touchpad.addEventListener("touchend", () => { + movementState.shouldResetTouch = true; + }); }