Domanda

I saw online this code used a lot:

public void onAccelerometerChanged(final AccelerometerData myAccelerometerData) {)

When I try to use it, eclipse will not recognize the AccelerometerData class.

I'm having a hard time:

  1. Detecting tilt.
  2. Using it to change the worlds physics with box2d.

It would help me if anyone could show me ways of detecting tilting and using it.

Thank you.

È stato utile?

Soluzione

You can see this code used in the PhysicsExample where it is used to change the center of gravity.

You must use the same code branch as the one in the example you have found. Notice that I linked GLES2-AnchorCenter branch version of the PhysicsExample. This branch is the newest. There is no AccelerometerData class. It has been renamed to AccelerationData.

Tilting (phone orientation) can be detected in a similar fashion. You have to call the following methods in your Activity and pass the correct listener.

    protected boolean enableOrientationSensor(final IOrientationListener pOrientationListener) {
            return this.mEngine.enableOrientationSensor(this, pOrientationListener);
    }

    protected boolean enableOrientationSensor(final IOrientationListener pOrientationListener, final OrientationSensorOptions pLocationSensorOptions) {
            return this.mEngine.enableOrientationSensor(this, pOrientationListener, pLocationSensorOptions);
    }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top