From 253f0336806772cae09bc6493d94a2fc2d85409d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Thunstro=CC=88m?= Date: Fri, 26 Apr 2013 21:36:11 +0200 Subject: [PATCH] Restrict the input from the gyro to the same range as desktop version. Also ensures that starting position when using gyro is "in the middle", and not the position corresponding to the top left corner when using mouse. --- js/plax.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/js/plax.js b/js/plax.js index 5ef60d7..8c202f2 100644 --- a/js/plax.js +++ b/js/plax.js @@ -31,6 +31,7 @@ layers = [], plaxActivityTarget = $(window), motionMax = 1, + motionMin = -1, motionStartX = null, motionStartY = null, ignoreMoveable = false @@ -168,6 +169,12 @@ // Admittedly fuzzy measurements x = values.x / 30 y = values.y / 30 + // Ensure not outside of expected range, -1 to 1 + x = x < motionMin ? motionMin : (x > motionMax ? motionMax : x) + y = y < motionMin ? motionMin : (y > motionMax ? motionMax : y) + // Normalize from -1 to 1 => 0 to 1 + x = (x + 1) / 2 + y = (y + 1) / 2 } var hRatio = x/((moveable() == true) ? motionMax : plaxActivityTarget.width()),