fix: mobile touch differentiates drag and tap
This commit is contained in:
parent
60c598c17d
commit
056daa6460
1 changed files with 38 additions and 14 deletions
|
|
@ -989,6 +989,11 @@ export function initWebGLBackground() {
|
||||||
pointer.active = true;
|
pointer.active = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const TOUCH_DRAG_THRESHOLD = 8;
|
||||||
|
let touchDragActive = false;
|
||||||
|
let touchStartX = 0;
|
||||||
|
let touchStartY = 0;
|
||||||
|
|
||||||
const renderEmitters = () => {
|
const renderEmitters = () => {
|
||||||
if (!emitterCtx || !emitterTarget) {
|
if (!emitterCtx || !emitterTarget) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -1449,31 +1454,50 @@ export function initWebGLBackground() {
|
||||||
pointer.active = false;
|
pointer.active = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener(
|
document.addEventListener("touchstart", (event) => {
|
||||||
"touchstart",
|
|
||||||
(event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
const touch = event.touches.item(0);
|
const touch = event.touches.item(0);
|
||||||
if (touch) {
|
if (touch) {
|
||||||
|
touchDragActive = false;
|
||||||
|
touchStartX = touch.clientX;
|
||||||
|
touchStartY = touch.clientY;
|
||||||
updatePointer(touch.clientX, touch.clientY);
|
updatePointer(touch.clientX, touch.clientY);
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
{ passive: false },
|
|
||||||
);
|
|
||||||
|
|
||||||
document.addEventListener(
|
document.addEventListener(
|
||||||
"touchmove",
|
"touchmove",
|
||||||
(event) => {
|
(event) => {
|
||||||
event.preventDefault();
|
|
||||||
const touch = event.touches.item(0);
|
const touch = event.touches.item(0);
|
||||||
if (touch) {
|
if (!touch) {
|
||||||
updatePointer(touch.clientX, touch.clientY);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!touchDragActive) {
|
||||||
|
const distance = Math.hypot(
|
||||||
|
touch.clientX - touchStartX,
|
||||||
|
touch.clientY - touchStartY,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (distance < TOUCH_DRAG_THRESHOLD) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
touchDragActive = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
updatePointer(touch.clientX, touch.clientY);
|
||||||
},
|
},
|
||||||
{ passive: false },
|
{ passive: false },
|
||||||
);
|
);
|
||||||
|
|
||||||
document.addEventListener("touchend", () => {
|
document.addEventListener("touchend", () => {
|
||||||
|
touchDragActive = false;
|
||||||
|
pointer.active = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener("touchcancel", () => {
|
||||||
|
touchDragActive = false;
|
||||||
pointer.active = false;
|
pointer.active = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue