Add touch control for mobile devices

This commit is contained in:
Marcel
2018-01-18 12:00:25 +01:00
parent b77baa06f7
commit 69a441189f
3 changed files with 27 additions and 1 deletions

24
touch-control.js Normal file
View File

@@ -0,0 +1,24 @@
const hammertime = new Hammer(document.getElementById("tetris"));
hammertime.on('swipeleft', () => {
keys.left.action();
});
hammertime.on('swiperight', () => {
keys.right.action();
});
hammertime.on('swipe', (e) => {
console.log(e.direction);
keys.down.action();
});
hammertime.on('tap', (e) => {
if (e.tapCount >= 2) {
keys.rotateRight.action();
}
});
hammertime.on('press', () => {
keys.down.action();
});