From: sh919.park Date: Tue, 18 Jun 2013 14:24:42 +0000 (+0900) Subject: [DeviceMotionCapture] Modify the coordinate formula X-Git-Tag: 2.2_release~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e360d70ca71f5bd9a53eb41e498cd4dca110ddab;p=samples%2Fweb%2FDeviceMotionCapture.git [DeviceMotionCapture] Modify the coordinate formula [Title] Modify the coordinate formula [Issue#] N_SE-40704 [Problem] The ball should not bounce on bottom right of the screen. [Solution] Modify the coordinate formula Change-Id: I86bc421ea88a1bc30a68b8d46e60bba32ca67d2c --- diff --git a/js/main.js b/js/main.js index efe9d5b..777655e 100755 --- a/js/main.js +++ b/js/main.js @@ -23,23 +23,23 @@ function deviceMotionEvents() { vx = vx * 0.98; vy = vy * 0.98; - x = parseInt(x + (vx / 20)); - y = parseInt(y + (vy / 20)); + x = parseInt(Math.round(x + (vx / 20))); + y = parseInt(Math.round(y + (vy / 20))); // Bound Check - if (x < 0) { + if (x <= 0) { x = 0; vx = -vx; } - if (y < 0) { + if (y <= 0) { y = 0; vy = -vy; } - if (x > document.documentElement.clientWidth - 80) { + if (x >= document.documentElement.clientWidth - 80) { x = document.documentElement.clientWidth - 80; vx = -vx; } - if (y > document.documentElement.clientHeight - 80) { + if (y >= document.documentElement.clientHeight - 80) { y = document.documentElement.clientHeight - 80; vy = -vy; }