Add swipe support. Modules can implement swipeLeft (etc). Swipes control movement in the World module (map).

This commit is contained in:
David Clark
2013-07-05 18:00:17 +10:00
committed by David Clark
parent 7f1efd4ad2
commit e9679b3f26
5 changed files with 761 additions and 2 deletions
+32 -1
View File
@@ -104,7 +104,14 @@ var Engine = {
// Register keypress handlers
$('body').off('keydown').keydown(Engine.keyDown);
$('body').off('keyup').keyup(Engine.keyUp);
// Register swipe handlers
swipeElement = $('#outerSlider');
swipeElement.on('swipeleft', Engine.swipeLeft);
swipeElement.on('swiperight', Engine.swipeRight);
swipeElement.on('swipeup', Engine.swipeUp);
swipeElement.on('swipedown', Engine.swipeDown);
Notifications.init();
Events.init();
Room.init();
@@ -542,6 +549,30 @@ var Engine = {
Engine.activeModule.keyUp(e);
}
return false;
},
swipeLeft: function(e) {
if(Engine.activeModule.swipeLeft) {
Engine.activeModule.swipeLeft(e);
}
},
swipeRight: function(e) {
if(Engine.activeModule.swipeRight) {
Engine.activeModule.swipeRight(e);
}
},
swipeUp: function(e) {
if(Engine.activeModule.swipeUp) {
Engine.activeModule.swipeUp(e);
}
},
swipeDown: function(e) {
if(Engine.activeModule.swipeDown) {
Engine.activeModule.swipeDown(e);
}
}
};
+17 -1
View File
@@ -316,7 +316,23 @@ var World = {
break;
}
},
swipeLeft: function(e) {
World.moveWest();
},
swipeRight: function(e) {
World.moveEast();
},
swipeUp: function(e) {
World.moveNorth();
},
swipeDown: function(e) {
World.moveSouth();
},
click: function(event) {
var map = $('#map'),
// measure clicks relative to the centre of the current location