1
votes

I'm using libgdx to render a map that is 32x32 tiles (with each tile being 32x32 pixels). I'm using the OrthogonalTiledMapRenderer for this. Then, I'm rendering a simple texture onto the screen that can move around using up/down/right/left. What I want is to get the position of the texture in terms of the map tiles positions. For example, if the texture is on top of tile (0, 0) I want to know this. So far, I've tried using camera.unproject(texcoordpositionVector) to get these, but it hasn't been working consistently.

Edit: here's how the map renderer and camera are setup:

SCALE = 10;
w = Gdx.graphics.getWidth();
h = Gdx.graphics.getHeight();

map = new TmxMapLoader().load("map.tmx");
camera = new OrthographicCamera(SCALE * (w / h), SCALE);
renderer = new OrthogonalTiledMapRenderer(map, 1/32f);

Then, to render:

camera.update();
camera.apply(Gdx.graphics.getGL10());
renderer.setView(camera);
renderer.render();
1
How did you setup your camera(s) and/or the map renderer's view? camera.unproject is the right place to start, but you may need to massage the result based on your unit scale. - P.T.
@P.T. I edited my question to include that information. - HRÓÐÓLFR

1 Answers

1
votes

If your texture is being drawn with the same camera as the map, then it should already be in tile space. If you are using a different camera, then you would need to project the position using that camera, then unproject it with the map camera.