Skip to content

Commit

Permalink
Fix touch controls
Browse files Browse the repository at this point in the history
  • Loading branch information
remvst committed Jul 30, 2021
1 parent ac8036a commit 5897437
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/index.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion docs/style.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
* {
margin: 0;
padding: 0;

user-select: none; /* supported by Chrome and Opera */
-webkit-user-select: none; /* Safari */
-moz-user-select: none; /* Firefox */
}

body {
background: #000;
overflow: hidden;
}

#can {
Expand All @@ -20,7 +25,7 @@ body {
}

#inner {

}

#container {
Expand Down
9 changes: 7 additions & 2 deletions src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ ontouchstart = (e) => {
onmousedown(e);
};

ontouchend = (e) => onclick(e.touches[0]);
ontouchmove = (e) => e.preventDefault();

ontouchend = (e) => {
onmouseup();
onclick();
}

onmousemove = (e) => {
const rect = CANVAS.getBoundingClientRect();
Expand All @@ -63,7 +68,7 @@ onmousemove = (e) => {
}
};

onclick = (e) => {
onclick = () => {
if (MENU) {
const button = MENU.highlightedButton(MOUSE_POSITION);
if (button) button.onClick();
Expand Down
7 changes: 6 additions & 1 deletion src/style.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
* {
margin: 0;
padding: 0;

user-select: none; /* supported by Chrome and Opera */
-webkit-user-select: none; /* Safari */
-moz-user-select: none; /* Firefox */
}

body {
background: #000;
overflow: hidden;
}

#can {
Expand All @@ -20,7 +25,7 @@ body {
}

#inner {

}

#container {
Expand Down

0 comments on commit 5897437

Please sign in to comment.