question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TmxLoader Changed it's behavior

See original GitHub issue

Hi Guys.

I found a backward compatibality issue in the 1.9.10 regarding Tmxloader.

I have <tileset firstgid="2" source="untitled.tsx"/> In my tmx file and all cells that are active have a 2 value (otherwise they have 0 value).

So , my code worked great before 1.9.10 version, but now I found, that all cells in all layers are null.

So, after some debugging, I found that now

<tileset firstgid="2" source="untitled.tsx"/>

not working as expected.

In this code.

protected void loadTileSet (Element element, FileHandle tmxFile, ImageResolver imageResolver) {
		if (element.getName().equals("tileset")) {
			String imageSource = "";
			int imageWidth = 0;
			int imageHeight = 0;
			FileHandle image = null;

			String source = element.getAttribute("source", null);
			if (source != null) {
				FileHandle tsx = getRelativeFileHandle(tmxFile, source);
				try {
					element = xml.parse(tsx);
					Element imageElement = element.getChildByName("image");
					if (imageElement != null) {
						imageSource = imageElement.getAttribute("source");
						imageWidth = imageElement.getIntAttribute("width", 0);
						imageHeight = imageElement.getIntAttribute("height", 0);
						image = getRelativeFileHandle(tsx, imageSource);
					}
				} catch (SerializationException e) {
					throw new GdxRuntimeException("Error parsing external tileset.");
				}
			} else {
				Element imageElement = element.getChildByName("image");
				if (imageElement != null) {
					imageSource = imageElement.getAttribute("source");
					imageWidth = imageElement.getIntAttribute("width", 0);
					imageHeight = imageElement.getIntAttribute("height", 0);
					image = getRelativeFileHandle(tmxFile, imageSource);
				}
			}

			String name = element.get("name", null);
			int firstgid = element.getIntAttribute("firstgid", 1);
			int tilewidth = element.getIntAttribute("tilewidth", 0);
			int tileheight = element.getIntAttribute("tileheight", 0);
			int spacing = element.getIntAttribute("spacing", 0);
			int margin = element.getIntAttribute("margin", 0);

			Element offset = element.getChildByName("tileoffset");
			int offsetX = 0;
			int offsetY = 0;
			if (offset != null) {
				offsetX = offset.getIntAttribute("x", 0);
				offsetY = offset.getIntAttribute("y", 0);
			}

			TiledMapTileSet tileSet = new TiledMapTileSet();

			// TileSet
			tileSet.setName(name);
			final MapProperties tileSetProperties = tileSet.getProperties();
			Element properties = element.getChildByName("properties");
			if (properties != null) {
				loadProperties(tileSetProperties, properties);
			}
			tileSetProperties.put("firstgid", firstgid);

			// Tiles
			Array<Element> tileElements = element.getChildrenByName("tile");

			addStaticTiles(tmxFile, imageResolver, tileSet, element, tileElements, name, firstgid, tilewidth, tileheight, spacing,
				margin, source, offsetX, offsetY, imageSource, imageWidth, imageHeight, image);

			for (Element tileElement : tileElements) {
				int localtid = tileElement.getIntAttribute("id", 0);
				TiledMapTile tile = tileSet.getTile(firstgid + localtid);
				if (tile != null) {
					addTileProperties(tile, tileElement);
					addTileObjectGroup(tile, tileElement);
					addAnimatedTile(tileSet, tile, tileElement, firstgid);
				}
			}

			map.getTileSets().addTileSet(tileSet);
		}
	}

the element before this line try { element = xml.parse(tsx); has an anttribute firstgid which value is 2, but after that line the element doesn’t have the firstgid , so in the following line int firstgid = element.getIntAttribute("firstgid", 1); the firstgid variable gets the 1 value instead of 2.

So , i changed all 2’s in my tmx to the 1, and it worked as expected.

Could you please guys look into it before a stable release of the 1.9.10 version ?

Thanks a lot.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
TCreutzenbergcommented, Jul 12, 2019

The issue should be fixed with this pull request: https://github.com/libgdx/libgdx/pull/5710 It worked fine when I was testing it.

2reactions
bachtrong43commented, Jul 24, 2019

@TCreutzenberg just created a new pull request.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TMXL Map Toolkit Buildables menu not appearing. : r/SMAPI
A couple weeks ago, I redid my mod set up and changed it back to it's F3 keybind and BOOM worked perfectly. A...
Read more >
bevy_tmx - Rust - Docs.rs
bevy_tmx is a plugin for the bevy game engine that allows you to read .tmx ... to the entities loaded from the .tmx...
Read more >
Stardew Valley Expanded - Nexus Mods
This mod adds 27 new NPCs, 50 locations, 260 character events, 27 fish, reimagined vanilla areas, two farm maps, a reimagined world map ......
Read more >
Davindius - GameDev.net
It can do 2D as well as 3D, in case you change your mind. ... It has a few examples in the github...
Read more >
Version History | Stardew Valley Expanded Wiki - Fandom
Changed the Wizard's arctic shard dialogue if married to the player. ... It's recommended players uninstall TMXLoader, PyTK, and Custom Music if no...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found