CompassHandler
Just for fun, we're going to provide an example that is similar to the AccelerometerHandler, but this time we'll give you the compass values along with the pitch and roll of the phone. We'll call the compass value “yaw,” since that's a standard orientation term that nicely defines the value we're seeing.
The only difference between the following code snippet and the previous accelerometer example is the change of the sensor type to TYPE_ORIENTATION and the renaming of the fields from “accel” to “yaw, pitch, and roll.” Otherwise, it works in the same way, and you can easily swap this code into the game as the control handler! Listing 5–6 shows you its code.
Listing 5–6. AccelerometerHandler.java; Performing All the Accelerometer ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access