Copy folder

This commit is contained in:
Andras Schmelczer 2022-09-26 12:30:36 +02:00
commit f40d182e88
7 changed files with 343 additions and 0 deletions

23
js/InputHandler.js Normal file
View file

@ -0,0 +1,23 @@
class InputHandler {
constructor(idOfWatchedArea) {
const elem = document.getElementById(idOfWatchedArea);
const handleMouse = ({ offsetX, offsetY }) =>
this.setPointerPosition([offsetX, offsetY]);
const handleTouch = ({ touches }) =>
this.setPointerPosition([touches[0].clientX, touches[0].clientY]);
elem.addEventListener("mousemove", handleMouse);
elem.addEventListener("touchmove", handleTouch);
this.pointerPosition = [0, 0];
}
setPointerPosition(newPosition) {
this.pointerPosition = newPosition;
}
get position() {
return this.pointerPosition;
}
}