2D Map Formats

Hello,

I am in the process of making a top-down 2d rpg, and was wondering how should I save the map as. At the moment I am just using a 1d int array, but would quite like to have more info, like solid etc. I read somewhere that xml is quite good?

Any ideas/tips appreciated

Max

Are you asking about the on-disk storage format, or the in-memory format? Because xml would be for disk storage, not runtime. Perhaps you could elaborate on your 1d int array method?

Storing a tile-based map? XML is not ideal for this, no. It might be good for map metadata, but you’re going to want to come up with a more compact format for the tile data itself. If you’re streaming in the map data in chunks, that’s also going to affect your format, so there’s no hard and fast answer that works for every map type.

how about simple text file?

Just a simple txt file is a good 1st step. Just write your array into your file element with a loop, and separate them with a comma (,). When you read in your map data, just read in the entire line and use String’s split to get your map in one go. Then you can loop through and for each one, use Integer.parseInt(splitArray[i]);

Of course, ideally it would be better to make a map editor that saves it in the right format.

I can recommend to take a good look at Tiled, which is a general 2D map editor that can store map data with XML and JSON. The data format of the grid can be plain or compressed.
There are at least 2 implementations in Java for reading this format as well.

xml makes more sense when you design your characterclasses, items etc.

for “matrix” data as the maps tiles use a more basic format, such as an 8bit-ascii textfile

you can also have a look at MAPPY as tile editor
http://tilemap.co.uk/mappy.php

thanks guys :smiley:
This format is for the game reading the file from an external folder and rendering it