Search code examples
javaandroidlibgdx

How to get coordinates of some points in my .TMX map? - LibGDX


I'm working on my game in LibGDX. I loaded my .TMX map to game, set a camera and a viewport. gameCam = new OrthographicCamera(); gamePort = new FitViewport(Marina.V_WIDTH / Marina.PPM, Marina.V_HEIGHT / Marina.PPM, gameCam) gameCam.position.set(gamePort.getWorldWidth() / 2, gamePort.getWorldHeight() / 2, 0); gameCam.position.x = 2.08f;// Here you have the starting cords of my camera. gameCam.position.y = 1.36f;

The problem is, when player touch one of the four egdes the camera is moving (4.16/-4.16 on X and 2.72/-2.72 on Y). For example, from 2.08/1.36 to 2.08+4.16/1.36 when the player touch the right edge.

My question is how to get cords of green points?

https://i.sstatic.net/w2Zjt.png


Solution

  • To get the edges of what the camera is seeing, you simply have to do this:

    Left edge: camera.position.x - (viewport.getWorldWidth() / 2)

    Right edge: camera.position.x + (viewport.getWorldWidth() / 2)

    Top edge: camera.position.y - (viewport.getWorldHeight() / 2)

    Bottom edge: camera.position.y + (viewport.getWorldHeight() / 2)

    I think I have answered your question