Adding Tilt with the Virtual Accelerometer Object

By Andy Harris

Part of HTML5 Game Development For Dummies Cheat Sheet

An HTML5 game programmer can use an accelerometer (the Accel object) to read tilt and movement input on supported devices, such as tablets and phones.

accelName = new Accel() Creates a new Accel object called
getAX() Returns rotation around the X axis as
a –1 to 1 value (often used to modify DY).
getAY() Returns rotation around the Y axis as
a –1 to 1 value (often used to modify DX).
getAZ() Returns rotation around the Z axis
(rotating the device like a steering wheel). Typically, the getAY() also returns suitable values for this
type of input, so getAZ() is rarely
getRotX(), getRotY(), getRotZ() Returns the current change in rotation around each of the axes.
Normally, the get() methods are more