I’m building a basic tile game containing 3 layers of ’tiles’
- The tiles itself
- Objects
- Items
image the game has a dimension of 3×3 my data array’s look like this:
public var tiles_Array:Array =
[ [1, 1, 1,],
[1, 2, 1,],
[1, 1, 1,],
];
public var objects_Array:Array =
[ [1, 3, 1,],
[5, 4, 1,],
[1, 7, 1,],
];
public var items_Array:Array =
[ [1, 1, 1,],
[1, 1, 8,],
[5, 1, 1,],
];
I’ve got 2 questions:
- How can i load this data from an external file which is easy to edit for the level-desiners ? (and what is best to use, xml, json, … ?)
- Is is not better to just use 1 datafile instead of 3 and what is the best way to do this ?
For the level data, any of the file formats you listed could work. I often use XML, but that’s mostly because Flash has built-in commands to handle XML so that’s slightly more convenient to parse. JSON also works fine through freely available libraries, or you could just roll your own file format and parse it using simple string commands. In the end this doesn’t really matter so long as your chosen file format is flexible enough to accommodate the inevitable future extensions (eg. you’ve added new types of entities to your game).
It is almost always better to store separate data as separate files because that gives you much more flexibility for how to manage the files. The one exception I can think of would be if you want to store the level data in a database, and that’s a pretty rare situation. I’ve never done that personally, but I know that would make sense for an online game with user generated levels.
Actually loading the file is done using a URLLoader as described here: http://www.kirupa.com/developer/flashcs3/using_xml_as3_pg2.htm
(Note: That only applies to separate flat-files. Levels stored in a database would require a completely different workflow, involving GET requests made to backend code on your server.)
For editing the data, the level designers should never be looking at the XML (or JSON or CSV or whatever) data directly and instead you would write a level editor for them to use, and that editor would have commands to load and save levels. If you’re using Air then you can save text files directly, but even without that you could simply have the editor dump out the data to a text field that you can paste into a file.