Skip to content

Commit

Permalink
Mobile: Prevent "ghost mouse click" on mobile devices
Browse files Browse the repository at this point in the history
  • Loading branch information
Auroriax committed May 25, 2022
1 parent 6642ecf commit 3e142aa
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/js/inputoutput.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ function onMouseDown(event) {
if (levelEditorOpened && !textMode) {
return levelEditorClick(event,true);
} else if ("mouse_left" in state.metadata) {
prevent(event)
return mouseAction(event,true,state.lmbID); // must break to not execute dragging=false;
}
}
Expand Down Expand Up @@ -720,6 +721,7 @@ function onMouseUp(event) {
if (event.target===canvas) {
setMouseCoord(event);
if ("mouse_up" in state.metadata) {
prevent(event); //Prevent "ghost click" on mobile
return mouseAction(event,true,state.lmbupID);
}
}
Expand Down Expand Up @@ -914,9 +916,9 @@ function onMouseOut() {
//console.log("Cursor moved out of canvas")
}

document.addEventListener('touchstart', onMouseDown, false);
document.addEventListener('touchstart', onMouseDown, {passive: false});
document.addEventListener('touchmove', mouseMove, false);
document.addEventListener('touchend', onMouseUp, false);
document.addEventListener('touchend', onMouseUp, {passive: false});

document.addEventListener('mousedown', onMouseDown, false);
document.addEventListener('mouseup', onMouseUp, false);
Expand Down

0 comments on commit 3e142aa

Please sign in to comment.