Android Accelerometer For Gaming

accelerometerandroid

I'm designing a game for Android and I would like to use the accelerometer for some aspects of control. Has anyone come across a tutorial or example for something like this?

Best Solution

AndEngine supports easy access to the acelerometer

You call this method to enable the Accelerometer with a listener:

this.enableAccelerometerSensor(this);

and this is how you react on changes of the accelerometer:

@Override
public void onAccelerometerChanged(final AccelerometerData pAccelerometerData) {
    this.mPhysicsWorld.setGravity(new Vector2(pAccelerometerData.getY(), pAccelerometerData.getX()));
}

(Taken from: http://code.google.com/p/andengineexamples/source/browse/src/org/anddev/andengine/examples/PhysicsExample.java )

Best Regards,

Nicolas