I am trying to print the coordinates in libgdx of the PLAY button that I touch Everything works well towards the X But the Y is upside down and not in the right direction either, it says it is between 173 and 312 But I drew the frost in 72 and its size is 64, how suddenly its size increased to 139 There is simply a mismatch between the axes and whaI am trying to print the coordinates in libgdx of the PLAY button that I touch Everything works well towards the X But the Y is upside down and not in the right direction either, it says it is between 173 and 312 But I drew the frost in 72 and its size is 64, how suddenly its size increased to 139 There is simply a mismatch between the axes and what is happening in reality In addition, it doesn't start drawing at 0.0, I'm starting to believe that maybe I have a problem with the version
public static final int V_WIDTH =400;
public static final int V_HEIGHT =208;
public class MainMenuScreen implements Screen {
private Game game;
SpriteBatch batch;
private OrthographicCamera gamecam;
private OrthographicCamera waterCam;
private Viewport gamePort;
private Viewport waterPort;
private TmxMapLoader mapLoader;
private TiledMap map;
TiledMap WaterMap;
private OrthogonalTiledMapRenderer renderer;
private OrthogonalTiledMapRenderer rendererWater;
Vector2 touchPosition;
Texture img;
Texture playButton;
public MainMenuScreen(Game game, SpriteBatch batch) {
this.game = game;
this.batch=batch;
img = new Texture("BG.jpg");
playButton = new Texture("play.png");
gamecam = new OrthographicCamera();
waterCam = new OrthographicCamera();
gamePort = new StretchViewport(LearningLetters.V_WIDTH,LearningLetters.V_HEIGHT,gamecam);
waterPort= new StretchViewport(LearningLetters.V_WIDTH,LearningLetters.V_HEIGHT,waterCam);
mapLoader = new TmxMapLoader();
map= mapLoader.load("start.tmx");
WaterMap = mapLoader.load("water.tmx");
renderer = new OrthogonalTiledMapRenderer(map);
rendererWater = new OrthogonalTiledMapRenderer(WaterMap);
gamecam.position.set((16+4)*16,gamePort.getWorldHeight()/2,0);
waterCam.position.set((16+4)*16,waterPort.getWorldHeight()/2,0);
}
@Override
public void show() {
}
public void update(float dt){
if(waterCam.position.x>(16+4)*16+128)
waterCam.position.x=(16+4)*16;
waterCam.position.x+=50*dt;
gamecam.update();
waterCam.update();
renderer.setView(gamecam);
rendererWater.setView(waterCam);
}
@Override
public void render(float delta) {
update(delta);
Gdx.gl.glClearColor(1,1,0,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(img,16*16/2-16,0);
batch.end();
batch.setProjectionMatrix(waterCam.combined);
batch.setProjectionMatrix(gamecam.combined);
rendererWater.render();
renderer.render();
batch.begin();
batch.draw(playButton,LearningLetters.V_WIDTH/2+64,LearningLetters.V_HEIGHT/2-64/2);
batch.end();
if(Gdx.input.isTouched()){
touchPosition = new Vector2(Gdx.input.getX(), Gdx.input.getY());
touchPosition.y=(Gdx.graphics.getHeight() - touchPosition.y)*64/Gdx.graphics.getHeight();
if (touchPosition.x > LearningLetters.V_WIDTH/2+64/2 && touchPosition.x < LearningLetters.V_WIDTH/2+64+64) {
if ( touchPosition.y > Gdx.graphics.getHeight() - LearningLetters.V_HEIGHT/2-64/2 - playButton.getHeight() && touchPosition.y < Gdx.graphics.getHeight() - playButton.getHeight() ) {
System.out.println(touchPosition);
}
}
}
// Render the main menu here
}
@Override
public void resize(int width, int height) {
gamePort.update(width, height);
waterPort.update(width, height);
}
@Override
public void pause() {
// Pause the main menu here
}
@Override
public void resume() {
// Resume the main menu here
}
@Override
public void hide() {
}
@Override
public void dispose() {
map.dispose();
// Dispose of the main menu here
}
}
t is happening in reality In addition, it doesn't start drawing at 0.0, I'm starting to believe that maybe I have a problem with the version
The solution was to look at the unproject coordinates of the camera and not the way I looked at them
I have no explanation why it really works but this is the solution I found