javalibgdxtiledtmx

libgdx: tiled map renders incorrectly when using multiple tilesets


I've been starting to work with libGDX to load tmx maps made using Tiled and have a weird issue where as soon as I use a second tileset my program stops displaying the map correctly, either showing nothing at all or using totally different tiles. This occurs even if no tiles from the other tileset are used, just having a second tileset tags screws it up. Everything still looks fine when opening it in Tiled and I'm not familiar enough with the tmx format to know if it's the renderer or the data that's messed up. The libGDX code I'm using is identical to the tutorial below but using different tilesets (both of which I've been able to render properly alone), although I've also tried other variations of the rendering code without any luck .

https://www.gamefromscratch.com/post/2014/04/16/LibGDX-Tutorial-11-Tiled-Maps-Part-1-Simple-Orthogonal-Maps.aspx

Map in Tiled

enter image description here

What I see running my program

enter image description here

The tmx file:

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.2" tiledversion="1.3.1" orientation="orthogonal" renderorder="right-down" compressionlevel="-1" width="32" height="32" tilewidth="16" tileheight="16" infinite="0" nextlayerid="4" nextobjectid="1">
  <tileset firstgid="1" source="sprites.tsx"/>
  <tileset firstgid="1025" source="tileset.tsx"/>
  <layer id="1" name="Tile Layer 1" width="32" height="32">
    <data encoding="base64">
    KgQAACoEAAAqBAAAKgQAACoEAAAqBAAAKgQAACoEAAAqBAAAKg...
    </data>
  </layer>
  <layer id="2" name="Tile Layer 2" width="32" height="32">
    <data encoding="base64">
    iQAAAMEBAADBAQAAwQEAAMEBAADBAQAAwQEAAMEBAADBAQAAw...
    </data>
  </layer>
</map>


Solution

  • This is a bug in latest release. It's fixed in master branch. see https://github.com/libgdx/libgdx/pull/5722

    You can temporarily use libgdx 1.9.11-SNAPSHOT to have it working.