May 102015
 

For a recent project, I had to create a game-style controller Android app that senses the phone’s tilt and uses it as an input.

http://i.stack.imgur.com/ylWJb.png (image via SO)

To simplify the explanation, imagine a jet thruster game where the farther you tilt the phone back, the stronger the jet thrusters fire:

  • When the phone sits upright, the thrusters don’t fire at all
  • When the phone is tilted all the way back, the thrusters fire at full force

Going into it, I knew I would need to use Sensors, specifically something about the Accelerometer. Digging in a bit more, no amount of Googling/Stack searching provided me with exactly what I was looking for, so I figured I’d write it up here…

Initial search results:

Solution

My fully open-sourced solution lives here: https://github.com/loisaidasam/tilt

Specifically, check out MainActivity.java:

A few notes:

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)