UNPKG

1.12 kBJavaScriptView Raw
1/**
2 * Holds the current orientation of the device if the device has an accelerometer. An instance of Accelerometer is available as {@link Splat.Game#accelerometer}.
3 * @constructor
4 */
5function Accelerometer() {
6 /**
7 * The angle of the device rotated around the z-axis. The z-axis is the axis coming out of the device screen. alpha represents how much the devies is spun around the center of the screen.
8 * @member {number}
9 */
10 this.alpha = 0;
11 /**
12 * The angle of the device rotated around the x-axis. The x-axis is horizontal across the device screen. beta represents how much the device is tilted forward or backward.
13 * @member {number}
14 */
15 this.beta = 0;
16 /**
17 * The angle of the device rotated around the y-axis. The y-axis is vertical across the device screen. gamma represents how much the device is turned left or right.
18 * @member {number}
19 */
20 this.gamma = 0;
21
22 var self = this;
23 window.addEventListener("deviceorientation", function(event) {
24 self.alpha = event.alpha;
25 self.beta = event.beta;
26 self.gamma = event.gamma;
27 }, false);
28}
29
30module.exports = Accelerometer;