2

LibGDX on my emulator shows origin, (0,0), at bottom left, but my device is at top left. Please help!

I modified the tutorial of two screens as my program and uses font.draw() to draw font at screen as menu. The drawing of fonts works fine, but the touchup + touchDown event that implements InputProcessor gives different system origin on device and emulator.

emulator: Android 4.0.3 level 15

device: Samsung Galaxy Nexus, android 4.2.1.

Should I switch from LibGDX to OpenGL ES 2?

Thank you very much!

Best Regards.

Community
  • 1
  • 1
Lai
  • 115
  • 1
  • 6
  • possible duplicate of [Changing the Coordinate System in LibGDX (Java)](http://stackoverflow.com/questions/7708379/changing-the-coordinate-system-in-libgdx-java) – bemeyer Dec 17 '13 at 08:57
  • 1
    Actually it isn't. What he asks is different, check my answer. @BennX – Daahrien Dec 17 '13 at 18:05

1 Answers1

3

The touchup an touchdown events in InputProcessor give you the actual pixel you clicked, with the device screen units. Starting at the top left corner. You should always unproject your touchs to camera coordinates.

  • Create a Vector3:

    Vector3 touchPoint = new Vector3();
    
  • Unproject it using your camera:

    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button){
        cam.unproject(touchPoint.set(screenX, screenY, 0));
    
  • And then use the touchPoint.x and touchPoint.y as your touch coordinates.

Daahrien
  • 10,190
  • 6
  • 39
  • 71