3

So I'm sitting here with a phone with a 800px wide screen.. and Gdx.graphics.getWidth() also returns 800 as it should..

But when I get coordinates from Gdx.input.getX() the highest number I get when touching the screen all the way to the left is around 780.. and around 20 in the right side..

So all my coordinates are wrong, so all my buttons and stuff are not working as they should etc.

Any idea what is going on?

cucurbit
  • 1,422
  • 1
  • 13
  • 32
  • 1
    Are you sure that you're tapping at the very very very end of the screen (which is nearly impossible)? Usually, your finger is large and is far wider than 20px. – UeliDeSchwert Jun 18 '14 at 12:36
  • You should not need `Gdx.input.getX()` at all. Usually for buttons you will use `scene2d` which has buttons and correctly handles all input events for you. – noone Jun 18 '14 at 12:49
  • ManuToMatic, I'm having it outputting the coordinate on all frames and I slowly move my finger over the edge of the phone and the last coordinate it outputs is 780 and not 800 as it should be. – user3752513 Jun 18 '14 at 14:48
  • Noone, my buttons of just textures, not "buttons". – user3752513 Jun 18 '14 at 14:49

2 Answers2

0

Try to unproject the coordinates.

Vector3 vec=new Vector3(Gdx.input.getX(),Gdx.input.getY(),0);
camera.unproject(vec);
// now use vec.x and vec.y instead of gdx.input.get...
Boldijar Paul
  • 5,405
  • 9
  • 46
  • 94
0

Your coordinates are calculated from the other direction so you have to use

float ClickY = GameHeight - Gdx.input.getY();
gariepy
  • 3,576
  • 6
  • 21
  • 34
Dragos Rachieru
  • 602
  • 8
  • 21