Libgdx Touch Coordination Confusion
Solution 1:
You'll need to use a camera to do this. If you're not using a camera, I'd highly recommend adding one in, as it makes things a lot easier. Simply call camera.setToOrtho(true)
, which will switch LibGDX's coordinate system to the one you want, (0,0) in the top left.
To do this with a certain viewport width and height other than what you get from Gdx.graphics.getWidth/Height(), you can call camera.setToOrtho(true, viewportWidth, viewportHeight)
.
Solution 2:
I don't know how to set it at top left corner but one thing you could is to convert input coordinate to libgdx coordinate. I hope that could help you or help somebody else :
intScreen_height= Gdx.graphics.getHeight(); // Your screen height @OverridepublicbooleantouchDown(int screenX, int screenY, int pointer, int button) {
System.out.println("X: " + screenX + " Y: " + (Screen_height - screenY));
this.instance.player.setLocation(screenX, (Screen_height - screenY));
returnfalse;
}
Solution 3:
Yes, and it's very easy. You just have to subtract from the Y value the height of the screen. So: The finger position Y = Heigh of the screen - the Y value you have found.
Solution 4:
There's an easier way: Just make the subtraction bellow
Gdx.graphics.getHeight()-screenY
Only this line of code is necessary, as you can see.
Solution 5:
Create the variable fingerY and use the subtraction:
fingerY= Gdx.graphics.getHeight()-screenY;
So, if screenY equals 10 from the left bottom corner and the height of the screen equals 240 pixels:
fingerY=240-10
Then fingerY=230 pixels from the bottom left corner, while it is 10 pixels from the top left corner.
Post a Comment for "Libgdx Touch Coordination Confusion"