Book Image

PhoneGap 3.x Mobile Application Development HOTSHOT

By : Kerri Shotts
Book Image

PhoneGap 3.x Mobile Application Development HOTSHOT

By: Kerri Shotts

Overview of this book

<p>PhoneGap allows you to use your existing knowledge of HTML, CSS, and JavaScript to create useful and exciting mobile applications.<br /><br />This book will present you with 12 exciting projects that will introduce you to the dynamic world of app development in PhoneGap. Starting with their design and following through to their completion, you will develop real-world mobile applications. Each app uses a combination of core PhoneGap technologies, plugins, and various frameworks covering the necessary concepts you can use to create many more great apps for mobile devices.</p>
Table of Contents (21 chapters)
PhoneGap 3.x Mobile Application Development HOTSHOT
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Accelerometer-based input


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.

Getting ready

First, we need to add a plugin to the project to support the accelerometer, as follows:

cordova plugin add org.apache.cordova.device-motion

Getting on with it

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,
            ...