In order to respond to the tilt of the device, we need to use the device's accelerometer. These aren't the easiest things to deal with, and our implementation is… a bit naive. Unfortunately it doesn't take long until you start getting into math that's more than a bit complicated and so lies outside the scope of this project.
First, we need to add a plugin to the project to support the accelerometer, as follows:
cordova plugin add org.apache.cordova.device-motion
Accelerometer-based input is hard, really hard, to get. It is so hard, in fact, that the game doesn't have a particularly good implementation of it. You are encouraged to experiment with a lot of devices and algorithms to come up with a good control scheme.
To turn on the accelerometer check, we first have to set up a watch for it in renderElement
, as follows:
self._tiltWatch = navigator.accelerometer.watchAcceleration ( self._updateAccelerometer, ...