summaryrefslogtreecommitdiff
path: root/game/plugins/orientation.js
diff options
context:
space:
mode:
Diffstat (limited to 'game/plugins/orientation.js')
-rw-r--r--game/plugins/orientation.js38
1 files changed, 19 insertions, 19 deletions
diff --git a/game/plugins/orientation.js b/game/plugins/orientation.js
index 77ad9fc..af5a649 100644
--- a/game/plugins/orientation.js
+++ b/game/plugins/orientation.js
@@ -13,26 +13,26 @@ var Orientation = function() {
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;
+ if (window.DeviceOrientationEvent) {
+ window.addEventListener('deviceorientation', 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.gamma = event.gamma;
+ previousEvent.beta = event.beta;
+ });
}
-
- window.addEventListener('deviceorientation', processOrientationEvent);
-}
+};
module.exports = Orientation;