mirror of
https://github.com/danog/2048.git
synced 2024-11-27 03:44:43 +01:00
add swipe gesture support
This commit is contained in:
parent
a44433df03
commit
b3c822c7d5
@ -6,12 +6,17 @@
|
|||||||
|
|
||||||
<link href="style/main.css" rel="stylesheet" type="text/css">
|
<link href="style/main.css" rel="stylesheet" type="text/css">
|
||||||
|
|
||||||
|
<script src="js/hammer.min.js"></script>
|
||||||
<script src="js/keyboard_input_manager.js"></script>
|
<script src="js/keyboard_input_manager.js"></script>
|
||||||
<script src="js/html_actuator.js"></script>
|
<script src="js/html_actuator.js"></script>
|
||||||
<script src="js/grid.js"></script>
|
<script src="js/grid.js"></script>
|
||||||
<script src="js/tile.js"></script>
|
<script src="js/tile.js"></script>
|
||||||
<script src="js/game_manager.js"></script>
|
<script src="js/game_manager.js"></script>
|
||||||
<script src="js/application.js"></script>
|
<script src="js/application.js"></script>
|
||||||
|
|
||||||
|
<meta name="HandheldFriendly" content="True">
|
||||||
|
<meta name="MobileOptimized" content="320">
|
||||||
|
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0, maximum-scale=1, user-scalable=no">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
9
js/hammer.min.js
vendored
Executable file
9
js/hammer.min.js
vendored
Executable file
File diff suppressed because one or more lines are too long
@ -47,6 +47,23 @@ KeyboardInputManager.prototype.listen = function () {
|
|||||||
|
|
||||||
var retry = document.getElementsByClassName("retry-button")[0];
|
var retry = document.getElementsByClassName("retry-button")[0];
|
||||||
retry.addEventListener("click", this.restart.bind(this));
|
retry.addEventListener("click", this.restart.bind(this));
|
||||||
|
|
||||||
|
// Listen to swipe events
|
||||||
|
var gestures = [Hammer.DIRECTION_UP, Hammer.DIRECTION_RIGHT,
|
||||||
|
Hammer.DIRECTION_DOWN, Hammer.DIRECTION_LEFT];
|
||||||
|
|
||||||
|
var gameContainer = document.getElementsByClassName("game-container")[0];
|
||||||
|
var handler = Hammer(gameContainer, {
|
||||||
|
drag_block_horizontal: true,
|
||||||
|
drag_block_vertical: true
|
||||||
|
});
|
||||||
|
|
||||||
|
handler.on("swipe", function (event) {
|
||||||
|
event.gesture.preventDefault();
|
||||||
|
mapped = gestures.indexOf(event.gesture.direction);
|
||||||
|
|
||||||
|
if (mapped !== -1) self.emit("move", mapped);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
KeyboardInputManager.prototype.restart = function (event) {
|
KeyboardInputManager.prototype.restart = function (event) {
|
||||||
|
Loading…
Reference in New Issue
Block a user