Add preventDefault to touch events to prevent double registered events on mobile devices

master
sigonasr2 4 years ago
parent cfc98df9a3
commit dd2ddf64ad
  1. 10
      game.js

@ -438,8 +438,8 @@ function setupGame() {
canvas.addEventListener("mousedown",clickEvent) canvas.addEventListener("mousedown",clickEvent)
canvas.addEventListener("mouseup",releaseEvent) canvas.addEventListener("mouseup",releaseEvent)
canvas.addEventListener("touchmove",updateMouse) canvas.addEventListener("touchmove",updateMouse)
//canvas.addEventListener("touchstart",clickEvent) canvas.addEventListener("touchstart",clickEvent)
//canvas.addEventListener("touchend",releaseEvent) canvas.addEventListener("touchend",releaseEvent)
document.addEventListener("keydown",keydownEvent) document.addEventListener("keydown",keydownEvent)
loadStage(STAGE2) loadStage(STAGE2)
} }
@ -477,6 +477,9 @@ function mouseOverButton(canvas,e,button) {
function clickEvent(e) { function clickEvent(e) {
//console.log(MENU.buttons) //console.log(MENU.buttons)
if (e instanceof TouchEvent) {
e.preventDefault()
}
if (MENU.visible) { if (MENU.visible) {
for (var button of MENU.buttons) { for (var button of MENU.buttons) {
if (mouseOverButton(canvas,e,button)) { if (mouseOverButton(canvas,e,button)) {
@ -535,6 +538,9 @@ function getGridCoords(pos) {
} }
function releaseEvent(e) { function releaseEvent(e) {
if (e instanceof TouchEvent) {
e.preventDefault()
}
if (SUBMENU.visible) { if (SUBMENU.visible) {
for (var button of SUBMENU.buttons) { for (var button of SUBMENU.buttons) {
if (mouseOverButton(canvas,e,button)) { if (mouseOverButton(canvas,e,button)) {

Loading…
Cancel
Save