summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Worthe <justin.worthe@entelect.co.za>2014-07-31 18:02:32 +0200
committerJustin Worthe <justin.worthe@entelect.co.za>2014-07-31 18:02:32 +0200
commit4f29b497e772d5cb9dd818c00adab8f634f5e7ad (patch)
tree6164312e24dd68ee7902b3e344c2764feb568448
parent887de9d0e29b35076ef138a474d5def3a9cb6179 (diff)
Made orientation actually work.
-rw-r--r--game/plugins/orientation.js36
1 files changed, 19 insertions, 17 deletions
diff --git a/game/plugins/orientation.js b/game/plugins/orientation.js
index af5a649..8ab922b 100644
--- a/game/plugins/orientation.js
+++ b/game/plugins/orientation.js
@@ -1,35 +1,37 @@
'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 self = this;
- var previousEvent = {
+ self.onLeft = new Phaser.Signal();
+ self.onRight = new Phaser.Signal();
+ self.onUp = new Phaser.Signal();
+ self.onDown = new Phaser.Signal();
+
+ self.previousEvent = {
gamma: 0,
beta: 0
};
- var threshhold = 15;
+ self.threshhold = 15;
if (window.DeviceOrientationEvent) {
- window.addEventListener('deviceorientation', function(event) {
- if (event.gamma < -threshhold && previousEvent.gamma >= -threshhold) {
- this.onLeft.dispatch();
+ window.addEventListener('deviceorientation', function(eventData) {
+ if (eventData.gamma < -self.threshhold && self.previousEvent.gamma >= -self.threshhold) {
+ self.onLeft.dispatch();
}
- if (event.gamma > threshhold && previousEvent.gamma <= threshhold) {
- this.onRight.dispatch();
+ if (eventData.gamma > self.threshhold && self.previousEvent.gamma <= self.threshhold) {
+ self.onRight.dispatch();
}
- if (event.beta < -threshhold && previousEvent.beta >= -threshhold) {
- this.onUp.dispatch();
+ if (eventData.beta < -self.threshhold && self.previousEvent.beta >= -self.threshhold) {
+ self.onUp.dispatch();
}
- if (event.beta > threshhold && previousEvent.beta <= threshhold) {
- this.onDown.dispatch();
+ if (eventData.beta > self.threshhold && self.previousEvent.beta <= self.threshhold) {
+ self.onDown.dispatch();
}
- previousEvent.gamma = event.gamma;
- previousEvent.beta = event.beta;
+ self.previousEvent.gamma = eventData.gamma;
+ self.previousEvent.beta = eventData.beta;
});
}
};