1

I am using Andengine and using SenorEvents to make a sprite move with the accelerometer.

But for some reason with this code, on tablet if i am in landscape mode which the game is made in, it acts as if it is in portrait mode.

Am i doing anything wrong? On a regular cell phone device, it works correctly

Here is what i have.

 sensorManager = (SensorManager) this.getSystemService(Arcade_MainGame.SENSOR_SERVICE);
         sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME);


  @Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub

}


@Override
public void onSensorChanged(SensorEvent event) {
synchronized (this) {
    switch (event.sensor.getType()) {
        case Sensor.TYPE_ACCELEROMETER:
            accellerometerSpeedX = (int)event.values[1];
            accellerometerSpeedY = (int)event.values[0];
            break;
    }
}

}
coder_For_Life22
  • 26,645
  • 20
  • 86
  • 118

2 Answers2

1

In your code, event.values[1] is supposed to be "Y" while event.values[0] have the value for "X" (you have them misplaced).

float x = event.values[0];
float y = event.values[1];
gian1200
  • 3,670
  • 2
  • 30
  • 59
1

On tablets and some smartphones default mode is landscape so when you declare that your game uses landscape then on tablets this is portrait mode. All you need to do is check default orientation and switch X with Y if there is landscape. Here is topic how to check it

Check orientation on Android phone

Community
  • 1
  • 1
Greg
  • 1,152
  • 1
  • 12
  • 28