I am a fairly new programmer and I’m currently working on a simple 2D RPG, written in c++. The maps are tile based and I love using the Tiled editor to create the maps!
At the moment, my maps save just very basic information: Position of tiles and objects (in any layer), collision, animated tiles (currently with a custom way I designed before realizing that one of the newer updates of Tiled added an animation feature - I will use the given feature now).
Without thinking about it, I saved the maps as *.tmx, because the tutorials I read also did that.
However, looking at the file size, TMX/XML seems to be relativly unefficient. My 100*100 TMX-Map is about 500kb large, while the same map ist only about 100kb large if saved as a JSON file.
I don’t know much about JSON. Is there any reason why maps are usually saved as TMX files? What are the advantages of TMX/XML compared to JSON?
Thanks in advance,
I’m sorry if there are any big language mistakes, because I’m not a native English speaker. I hope you understand my question
You must have set the “Tile layer format” to “XML” when you created the map for the file to get that large. When you leave it on the default “Base64 (zlib compressed)”, you should see that the TMX file is actually much smaller than your JSON file. The “CSV” setting should yield relatively the same size because the JSON file essentially also uses CSV for storing tile layer data.
You can change the tile layer format of existing maps via Map → Map Properties → “Tile Layer Format”. This property only affects the TMX file format.
You have step 2 and 3 in the wrong order. The base64 encoding encodes the binary data in a way that it can be embedded in the XML file. After decoding it, it needs to be decompressed.
Also, this process only applies to each tile layer. The rest of the file is still plain XML. The result of decompressing the tile layer data is not XML, but binary data where each 4 bytes make up one global tile ID.