Permalink
Browse files

adding some tests against a browser that doesn't support the accelero…

…meter
  • Loading branch information...
1 parent 7fd649d commit d5e75e51d185e4b0b58b08b8ea0bae2ef60cecc0 Danny Yoo committed May 1, 2012
Showing with 9 additions and 6 deletions.
  1. +9 −6 lib/world/jsworld/jsworld.js
@@ -904,7 +904,7 @@ var jsworld = {};
var wrappedTilt;
var beta = 0, gamma = 0;
var tickId;
- var delay = 1000 / 5; // Send an update ten times a second.
+ var delay = 1000 / 5; // Send an update five times a second.
var update = function() {
change_world(function(w, k) { tilt(w, gamma, beta, k); }, doNothing);
@@ -914,7 +914,10 @@ var jsworld = {};
wrappedTilt = function(e) {
preventDefault(e);
stopPropagation(e);
- beta = e.beta; gamma = e.gamma;
+ // Under web browsers that don't have an accelerometer,
+ // we actually get the null values for beta and gamma.
+ // We should guard against that.
+ beta = e.beta || 0; gamma = e.gamma || 0;
};
return {
@@ -933,11 +936,11 @@ var jsworld = {};
preventDefault(e);
stopPropagation(e);
if (!e.gamma && !e.beta) {
- gamma = e.x * 90;
- beta = e.y * (-90);
+ gamma = e.x * 90 || 0;
+ beta = e.y * (-90) || 0;
} else {
- gamma = e.gamma;
- beta = e.beta;
+ gamma = e.gamma || 0;
+ beta = e.beta || 0;
}
};
return {

0 comments on commit d5e75e5

Please sign in to comment.