I’ve been working on creating a 2D simulation that uses several images for individual layers of the map (floor, walls, doors, etc.). I wanted to use Tiled as the output because I also use Cocos2d-x, and it has a native importer for Tiled files (as do other frameworks).
One of the problems I ran into was automatically importing an image, slicing it up, merging the tiles, and then having the tiles displayed with the proper orientation (e.g. Image -> Completed Tilemap in the existing document). I have found the existing set of scripts that do this (Import From Image).
I’m curious if this feature is going to be imported directly into Tiled?
I wrote a python script to do this (take up several files and turn it into a .tmx file with a single tileset). You can find it on github (https://github.com/NonlinearIdeas/Map-Tiler).
One of the problems with the workflow is that you overwrite your files (intentionally or accidentally) when you change your map and run the process again. I am thinking about modifying the script to look into the existing .tmx file and do a “merge” type of operation instead.
I think the best approach, if the .tmx file already exists and the user has selected the “merge” option, is to keep the original file and merge in pieces of information from the newly created data set. This has the best chance of keeping everything intact.
- If the new map is different sized than the old map, abandon or overwrite based on user input.
- Overwrite or merge is controlled by user input.
- Object Layers are not created by the import process, so any already present in the tilemap should remain.
- Tileset properties should be preserved from the original .tmx file.
- All layers and layer properties should be preserved.
I have already written the script to do the generation. I am looking for feedback on whether the “merge” feature would be useful to others before I go into it (I don’t need it currently).
At the very least I would want to support opening images as tilemaps in Tiled, where it will automatically create a tileset that contains all the unique tile images. So far this just hasn’t become a priority and there’s just too many other things to work on.
Actually allowing the user to later update such a map from a modified image but keeping certain other additions is an interesting use-case that I’m sure would be useful to some people. However, I can’t say whether it is worth your time or whether you will actually find anybody who could use such a feature. It sounds so specific that personally I’d first want to make Tiled scriptable and allow such a thing to be implemented by a script.
Thanks for the feedback.
I already put a prototype implementation of the merge feature into place. It just takes the .tmx file that already exists and augments the gid tags for the new tileset created (and only for layers that were explicitly processed). The workflow expects that there will be only one tileset per map (reasonable, because all the layers are in the tileset). Expanding it to handle multiple tilesets is certainly feasible (just need to move all the gids around), but I got a little distracted at that point ;).
I usually work in C++ or C#, but I did this in Python so I could get it done rapidly (Python is good for rapid prototyping). Time is valuable, as you said. The algorithms used in the Python code are relatively benign, so at least you have a prototype implementation if you were interested in using it. There are Qt equivalents for cropping and rotating images, so the only secret sauce is comparing two images to see if they are the same (to remove duplicates).
It sounds useful enough to link it from the “related tools” section on Home · mapeditor/tiled Wiki · GitHub. Feel free to add a link there if you think it could help others with similar needs.
Right, in fact Qt also provides a
QImage == operator that does a deep comparison, though for performance reasons one would generally want to use a hash table lookup to check whether an image is new. It could be that
QHash<QImage, ...> already works as well, but if not it could be made to work.
Thanks for testing the waters with this approach and sharing your implementation. It will definitely help bringing this feature into Tiled, when that ever happens.
Not being a Qt developer, I didn’t realize the == operator would do that. But that sounds excellent, so the secret sauce is not secret.
After a few false starts (I have a bit of a blind spot for certain technologies), I updated the wiki page to have the link to my github post. It is still in active development, but already has yielded some fruit, so I am optimistic. Once it is in a “completed” state, I can get back to the reason I wrote the script in the first place ;).