1
\$\begingroup\$

Im using Tiled map editor, Hexagonal(staggered) map, libgdx version 1.9.9

If I set staggeredIndex = even in tiled map editor, libgdx seems to render odd

If I set it to odd in map editor, libgdx renders even

Screen Shots: enter image description here enter image description here

Here's the code:

@Override
public void create () {
    map = new TmxMapLoader().load("mapa.tmx");
    cam = new OrthographicCamera(Gdx.graphics.getWidth(),Gdx.graphics.getHeight()); 
    mapRenderer = new HexagonalTiledMapRenderer(map);

}

@Override
public void render () {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    cam.update();
    mapRenderer.setView(cam);
    mapRenderer.render();
}
\$\endgroup\$
1
\$\begingroup\$

Since I found the problem ima go ahead an answer my own question.

The tile(0,0) in Tiled is in top-left corner while in libgdx tile(0,0) is down-left corner.

This is why staggeredY axis causes problem in a map where the height is even like 10 tiles, in the map editor the first row is even and the last row is odd in libgdx the last row is actually the first row, so its even.

Solution: Make the map height odd, instead of 10 tiles I made it 11. You could make small changes to HexagonalTiledMapRenderer like

if(mapHeight % 2 === 0)
  staggerIndex = !staggerIndex

I just didn't mind adding an extra row.

I personally think they should correct this in libgdx

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.