hacky solution to fix cursor from rubberbanding when starting a new touch

This commit is contained in:
hippoz 2021-10-28 04:04:22 +03:00
parent c56d83881a
commit cc9ae32777
No known key found for this signature in database
GPG key ID: 7C52899193467641

View file

@ -103,17 +103,26 @@
currentX: 0, currentX: 0,
currentY: 0, currentY: 0,
lastCheckedX: 0, lastCheckedX: 0,
lastCheckedY: 0 lastCheckedY: 0,
shouldResetTouch: false,
} }
touchpad.addEventListener("touchmove", (event) => { touchpad.addEventListener("touchmove", (event) => {
movementState.currentX = event.touches[0].clientX; movementState.currentX = event.touches[0].clientX;
movementState.currentY = event.touches[0].clientY; 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 deltaX = movementState.currentX - movementState.lastCheckedX;
const deltaY = movementState.currentY - movementState.lastCheckedY; const deltaY = movementState.currentY - movementState.lastCheckedY;
movementState.lastCheckedX = movementState.currentX; movementState.lastCheckedX = movementState.currentX;
movementState.lastCheckedY = movementState.currentY; movementState.lastCheckedY = movementState.currentY;
connection.sendMessage("r", [deltaX, deltaY]); connection.sendMessage("r", [deltaX, deltaY]);
}); });
touchpad.addEventListener("touchend", () => {
movementState.shouldResetTouch = true;
});
} }
</script> </script>