Tilesheet auto-detect tiles with same image data

Is there a way in Tiled, or perhaps via existing third party utility, to loop over a Tiled Map Tilesheet to check for duplicate image data and assign each said duplicate tile the same set of properties?

For example, in the case of a huge existing tilesheet image say (ie- single PNG image) there are many tiles that are the same.

You can easily import the single PNG and setup a Tilesheet with separated tiles depending on the dimensions you want it sliced up - however…

for my game, I require each tile to have a custom property “name”. This name can and should be the same for all tiles of the same basic image data. The problem is in Tiled the only way I can find to accommodate for applying a name to duplicate tiles in this manner is by selecting them and applying the property “name” one at a time…

you can of course select multiple tiles and apply a custom property to all of those tiles in your selection to speed up the process - but still I am finding this is tedious given the size and variety/placement of these duplicate tiles in my massive tilesheet. Also ripe for error; as a programmer I’d prefer not to have to eye things out or potentially miss a tile that should have been labelled.

What I’d like to do is minimize the manual work to just finding ONE unique tile and applying my custom “name” property to each thereof and let Tiled (or third party util) auto-detect the rest of the duplicates in the Tilesheet and adopt/inherit that same custom property from the corresponding manually labelled one.

Hope this makes sense; and if anyone knows a tool that can do this I’d be keen to try it!

Otherwise am thinking about writing a script to do this but just wanted to see if this has been done before going down that rabbit hole.

Tiled can’t do this because it does no image processing other than displaying them.

Pyxel Edit (and perhaps other tile-oriented image editors?) can import images as tilesheets and ignore duplicates, and you could then export that as a new tileset image that’ll have only unique tiles. That will break your existing maps though, and it sounds like you want to keep the repeats.

You’ll probably have to write your own tool to do this, since you not only want to find duplicates, but also deal with Tiled’s Tileset files ): Fortunately, this isn’t a very complex task, just a potentially slow one since you’ll need to hash or otherwise compare pixel data for many tiles, and you might want to add a GUI to prompt the user (yourself) for the names of particular tiles.

1 Like

Thanks @eishiya ! Great tips. That is good thinking ie- using something like Pyxel Edit however you are also right that I want to keep the repeats.

I wonder if there is a quick hack that would help me see visually in Tiled Tilesheet editor window what tiles do not yet have a name/property ? For example, if there was a way to hide tiles that have property or a certain property. Either via Tiled; with help of some editor that can export a modified tmx or by editing the tmx directly…

I just discovered Types which is great for applying a set of properties and notice that you can assign a ‘color’ value to each type but that doesn’t appear to reflect in the Tilesheet editor; it would be awesome if one could toggle those colors on as an overlay; in this case it would let me see what tiles are remaining/need to have properties assigned.

1 Like

Unfortunately there isn’t any graphical display for properties currently. I think terrains and the tile animation icon are the only things that get displayed on the tileset.

I suppose you could use Terrains for labelling, assigning a full block of that terrain to each tile, with the terrain being the name of the tile, or just a general “I’ve named this” terrain. The former would make your parsing more complicated since you’d need to get the tile’s name from the terrain data rather than have it be in the tile’s properties but would be more convenient to actually do in Tiled. The latter is more tedious in Tiled since you’d need to both set the name and mark the tile with the terrain, but doesn’t change your code any, can play along with existing Terrains if you’re using them, and definitely won’t run into Tiled’s limit of 256 terrains.

1 Like

Thanks again for the tips.

I found these Node modules that may be useful for creating a custom script.

First, to divide up the single tilesheet graphic into separate files one per each tile (unless Tiled has a standard way to do this?)

second, to analyze/compare each said tile graphic file:

if I get the motivation to make this - I would just make it a standalone script to do the operation on the Tiled tsx file directly - though if you think it’s wortwhile/other people may be interested at that point could certainly look into Tiled’s plugin/script API to see about making it available as a plugin.