summaryrefslogtreecommitdiff
path: root/game/plugins
diff options
context:
space:
mode:
authorJustin Worthe <justin.worthe@entelect.co.za>2014-07-31 16:45:33 +0200
committerJustin Worthe <justin.worthe@entelect.co.za>2014-07-31 16:45:33 +0200
commit0a4b32158d6ddd17eb9df21ff5940c736eb8208e (patch)
treedfba00090556cbb2baf2e4a99d7c3929c0341b49 /game/plugins
parenta5718bd0e29a6245d2e82a272a616782187ee283 (diff)
Attempt at adding orientation based input
Diffstat (limited to 'game/plugins')
-rw-r--r--game/plugins/orientation.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/game/plugins/orientation.js b/game/plugins/orientation.js
new file mode 100644
index 0000000..77ad9fc
--- /dev/null
+++ b/game/plugins/orientation.js
@@ -0,0 +1,38 @@
+'use strict';
+
+var Orientation = function() {
+ this.onLeft = new Phaser.Signal();
+ this.onRight = new Phaser.Signal();
+ this.onUp = new Phaser.Signal();
+ this.onDown = new Phaser.Signal();
+
+ var previousEvent = {
+ gamma: 0,
+ beta: 0
+ };
+
+ var threshhold = 15;
+
+ var processOrientationEvent = function(event) {
+ if (event.gamma < -threshhold && previousEvent.gamma >= -threshhold) {
+ this.onLeft.dispatch();
+ }
+ if (event.gamma > threshhold && previousEvent.gamma <= threshhold) {
+ this.onRight.dispatch();
+ }
+ if (event.beta < -threshhold && previousEvent.beta >= -threshhold) {
+ this.onUp.dispatch();
+ }
+ if (event.beta > threshhold && previousEvent.beta <= threshhold) {
+ this.onDown.dispatch();
+ }
+
+
+ previousEvent = event;
+ }
+
+ window.addEventListener('deviceorientation', processOrientationEvent);
+}
+
+
+module.exports = Orientation;