Small clean up
This commit is contained in:
parent
3b807a968c
commit
3640242506
2 changed files with 31 additions and 16 deletions
|
|
@ -1,14 +1,18 @@
|
|||
class InputHandler {
|
||||
constructor(idOfWatchedArea) {
|
||||
const elem = document.getElementById(idOfWatchedArea);
|
||||
constructor(canvasHandler) {
|
||||
const elem = canvasHandler.canvas;
|
||||
|
||||
const handleMouse = ({ offsetX, offsetY }) =>
|
||||
this.setPointerPosition([offsetX, offsetY]);
|
||||
const handleTouch = ({ touches }) =>
|
||||
this.setPointerPosition([touches[0].clientX, touches[0].clientY]);
|
||||
const handleMouse = ({ clientX, clientY }) =>
|
||||
this.setPointerPosition(canvasHandler.clientToCanvas(clientX, clientY));
|
||||
|
||||
const handleTouch = (event) => {
|
||||
event.preventDefault();
|
||||
const { clientX, clientY } = event.touches[0];
|
||||
this.setPointerPosition(canvasHandler.clientToCanvas(clientX, clientY));
|
||||
};
|
||||
|
||||
elem.addEventListener("mousemove", handleMouse);
|
||||
elem.addEventListener("touchmove", handleTouch);
|
||||
elem.addEventListener("touchmove", handleTouch, { passive: false });
|
||||
|
||||
this.pointerPosition = [0, 0];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue