Add touch control for mobile devices
This commit is contained in:
24
touch-control.js
Normal file
24
touch-control.js
Normal 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();
|
||||
});
|
Reference in New Issue
Block a user