1

I'm programming a button in LIBGX. It works good on desktop, but when I launch it on android, I have to touch in a different place to trigger it (Im using a real Android device, not an AVD) Here's a pic describing it:

enter image description here

Below the TouchDown code:

Gdx.input.setInputProcessor(new InputAdapter () {
       public boolean touchDown (int x, int y, int pointer, int button) {
          // your touch down code here
         Vector3 coords = new Vector3(x, y, 0);
         camara.unproject(coords);

          if(coords.x >= 52 && coords.x<=129 && coords.y >= 158  && coords.y<=253){
              shoot(1);
          }
          return true; // return true to indicate the event was handled
       }
    });

I had the same problem without Vector3, I started using it because it was adviced, but didn't solve much. Here's the declaration of the camera:

camara = new OrthographicCamera();
camara.setToOrtho(false, 800, 480);

I have done some research, but can't find the right solution, and I find the cameras (ortographic, real world, etc) very confusing. I will keep digging, this has taken hours and had to make the question. I hope someone can point me in the right direction.

Victor
  • 907
  • 2
  • 17
  • 42
  • 1
    Not sure if I can help you directly, but I can tell you, that x and y coordinates on Android is somewhat inverted compared to a computer. The x and y coordinates starts in the upper left corner and not the lower left corner as on other operating systems. See: http://stackoverflow.com/questions/11483345/how-android-screen-coordinates-works for a bit more explanation (sorry couldn't find anything directly from the documentation). – Darwind Aug 28 '14 at 19:26

1 Answers1

1

Please note that the origin (0,0) in Android screen is situated at top-left corner of the screen. Thus, when you add values to y axis the object go towards bottom and when subtract values the object goes upwards.

In Android devices:

 Origin
 |
 V
 *-------------------------------
 | ----> X axis                  |
 | |                             |
 | |                             |
 | V Y-axis                      |
 |                               |
 |                               |
 |                               |
 |                               |
 |                               |
 |                               |
 |                               |
 |                               |
 |                               |
 |                               |
 |                               |
 |                               |
 |                               |
 |                               |
 |                               |
 |                               |
  -------------------------------

In desktops:

 --------------------------------------------------------------
 |                                                             |
 |                                                             |
 |                                                             |
 |                                                             |
 |                                                             |
 |                                                             |
 |                                                             |
 |                                                             |
 |                                                             |
 |                                                             |
 |                                                             |
 |                                                             |
 |                                                             |
 |                                                             |
 |                                                             |
 |                                                             |
 | ^ Y axis                                                    |
 | |                                                           |
 | |                                                           |
 | ----> X axis                                                |
 *-------------------------------------------------------------
 ^
 | 
 Origin   

Possible History:

As screen space calculations started when television sets were used as screens. The raster gun of a TV is also starting at the top left corner, so this was accepted as the origin.

For further reference you can refer here

Community
  • 1
  • 1
TryinHard
  • 4,078
  • 3
  • 28
  • 54