Tiled map editor export to Defold (SOLVED-ish)

Sorry for my stupid question, but how i can add tilemap created in Tiled map editor to my project in Defold?
I tryed add it like a tilemap created in Defold but i cou`d not see the files in any of format exported from Tiled.
If it possible give some wery short manual of working Tiled with Defold.

3 Likes

Hi,

Go to Preferences in Tiled then plugins and enable the libdefold.dylib by ticking it.

You can then export as Defold *.tilemap format

4 Likes

Oh, thank you, it turned out to be very simple.

3 Likes

Precision : under linux you should add the package : tiled-plugin-defold

Hello. Thank you for Defold editor. I have question related to the subject of this thread.

I do not know is it expected, but it looks like Tiled plugin for Defold does not working as it should. After export tile_set property in .tilemap is empty string, and there are only one file .tilemap is generated. I suppose there are should be .tilesource as well.
Also it is unexpected how it will work with Tiled “images collection based” tilsets (where you able select multiple images instead of compound sprite sheet with tiles). It does not looks like Defold tilemap can use collection of separate images to build maps.
Who maintain this plugin? Is it opensource and available for community improvements?

Defold tile map editor still luck of required features such as sprite rotation, random brash, fil bucket, region mask selection which are part of Tiled, so it is critical to have ability to support this editor. At least ability to use tmx files itself will be nice.

Is it good idea to write my own tmx file parser and load tmx and tsx files from code or there will be some gotchas related to the Defold architecture? Can i expect good performance doing this? Why Defold team take decision to write it’s own tile map editor inside editor and reject to use widely used well known Tiled editor files formats?

There’s this PR for an improved exporter:

Maybe you can contribute to it or help test it?

It is open source.

Isn’t it better to export to .json or .lua as that would be easier to parse?

Yes, it should be fast.

The tilemap solution used in Defold was created 7 years ago. I’m not sure how old Tiled is, it’s been around for quite some time as well, but the decision that was taken all those years ago was on the format we have today. The good thing about the format is that it is human readable and easy to parse. This means that it’s possible to create offline converters from Tiled to Defold. Or read for instance a Tiled .json export at runtime and populate the tilemap that way.

3 Likes

You can check out my demo project of Tiled Lua import into Defold.

3 Likes

@britzl thank you for answers. I will check plugin repo if i can commit into development and testing.
Tiled first been release in 2003, but i do not think it was very famous until 2010.

@sergey.lerg that will be helpful, TYVM.

3 Likes

I’ve started playing with the Tiled to .collection exporter, and so far it seems more magical than I had hoped. It supports rotating tiles! Magic.

Is there a list of supported features for this export? One thing, for instance, is objects. Being able to get an object id and coordinates would open up many exciting possibilities. I don’t think this is supported after a few tests, but may be wrong?

1 Like

Could you export that in a separate step as json or Lua from Tiled?

I suppose so, if need be. For now, I’ll use placeholder tiles and get them with tilemap.get_tile(). This requires you to scan the entire tilemap, so a little heavy.

1 Like

Not so fast - the tiles are rotated inside the editor, but when the app is run the tiles are not rotated. What’s up with that?

In Tiled:
03

In Defold IDE:

When run:
50

1 Like

Presumably because there is some kind of rotation meta data in tiled? But Defold tiles don’t support rotation of tiles does it? I don’t remember… it’s strange that the editor picks up on it but not the engine.

You can use animations to make multiple rotations without adding the rotation images themselves.

Not rotation, but mirrored tiles. The .collection export takes this into account, and uses it for rotation. It works everywhere aside from in game.

How do you mean?

I’m mistaken, tile sources support animations, but not tile maps. Animation support was requested years ago. :slight_smile:

There isn’t a way in the builtin editor to flip tiles horizontally and vertically either but maybe it was planned but not implemented in the engine?

I was curious about that too. Turns out you can flip tiles via tilemap.set_tile(), but it’s weird that you can’t do that in the editor.

We have this on our list of things we really should support soon. We’ll keep you updated on this!

3 Likes

Now it seems even more strange that the data works in the editor but not in the engine, but if you manually set the tile in the engine it works?

Investigation time!

Just like what @totebo found, manually flipping the tiles by editing the tilemap file makes the tiles appear flipped in the Defold editor, but not in-game. Flipping tiles via tilemap.set_tile() works perfectly fine, but of course it only shows up in-game. If someone really wanted to, they could probably make an editor script to scan tilemap files and output a table containing coordinates of tiles to be flipped by a script.

Screenshots

Left: unflipped tiles | Right: Horizontally flipped tiles
-----------------------------------

Manually flipped tiles in editor:
h-flipped_in_editor

Manually flipped tiles in game:
h-flipped_in_game

Tiles flipped via script in game:
h-flipped_in_script

1 Like

We will fix this in 1.2.169. Adding tile flipping support in the editor will have to come later.

4 Likes