Best practices for level storing and loading

11 posts

Flag Post

Hi there,

I’d like to know if you have links to interesting articles about best practices in level storing and loading in AS3, and level editors. Not only level structure, but also enemies position, patterns, triggers and stuff to be spawned.

I usually store and load them from XML or JSON files, but I’m not sure about how to structure them to make it more efficient.

Thanks!

 
Flag Post

Well, I looked at size of data for levels since I had a 30×30 grid with 3 or 4 layers (this would be for Ninja Sequence if you saw any pictures).

I was able to use byte arrays and Base64 to compress this data down to just a string.

Simple levels compressed down a lot, but more complex levels took up more space since they had less contiguous segments (places in the map where the tiles were the exact same id number).

A sample of the data from each level (these are fairly simple levels)

public static const LEVEL_1:String = "7dbBCoAgDADQH5JoJFH/5sdHt04RqYH00JOH5xxjLkqJNcVe5tRpTWQyuVaO5W43u+PBUTN7Ro9Ld6/Bd49g1/UVrZbccBkryWRyRzmfn1i3mFvK+epugwT9lTxG2UUeMOisc5DNjPJMJpPJZDKZbGKUZzKZTCaTyeSfTIwH";
public static const LEVEL_2:String = "7dZRCoAgEAXAC0m0ZXQ5D98B+kjMpGLQX8d1RXxRyrKnWMqcHhoTmUy+I8faMpv3uiqUzWbXLhzwPCvOxPYRvUAWM8lk8iA5cmc6dy46u8IPy1k3hsmxdafjNDRaZiSTyWQymUwmS4z6TCaTyWQymfy3xHgA";
public static const LEVEL_3:String = "7dY7DoAgDADQCxlj4yfxbhzezcFFQUlEX8oCwytpCmmkFEsXaxq6StGTyeR7coyFqzDZ+W3Z7dkXN2/V9/2xtf9Zm7znX5jHN0yuFEZOMpnckDxlnqvzf+SYchrikUvHXIWOPXQH2cxIJpPJZDKZTDYxqjOZTCaTyWTydybGDQ==";

Also, I’m not going to claim this is the best way to do it, but it sure is a good way if you need to look at size of each level.

 
Flag Post

Interesting. What about the level creation part? What did you use?

Has someone had any experience with GLEED2D? http://gleed2d.codeplex.com/

 
Flag Post

I actually wrote my own level editor that had a list of tiles and basic level creation features like loading, exporting, dynamic testing, etc.

 
Flag Post

It’s very unlikely that level definitions add significantly to the size of your SWF, or that level loading takes a problematically long time, even using something as verbose as XML. However, it’s pretty straightforward for someone to read your level definitions if you embed them as XML or another plain text format, so if you really care about that, you should maybe use some compression to avoid it.

I’ll be watching this thread with interest as I’m having a similar discussion with myself regarding level editing and storage in my platform engine. I currently have an editor which creates XML (and lets you test the level, drag objects around etc) and I embed that XML file in the SWF.

 
Flag Post
Originally posted by UnknownGuardian:

I actually wrote my own level editor that had a list of tiles and basic level creation features like loading, exporting, dynamic testing, etc.

wow this i gotta see.

 
Flag Post
Originally posted by UnknownGuardian:

I actually wrote my own level editor that had a list of tiles and basic level creation features like loading, exporting, dynamic testing, etc.

Is is game-specific or just work for any project?

I’ve seen a lot of people building their level editor using AIR, like the Citrus Engine’s level architect, probably because of the more seamless interaction with the system.

Also, some people prefer to keep game and level editor together, while others keep them separated, which I think is the best approach.

 
Flag Post

There’s also Ogmo Editor for creating tile based levels. You can also add entities to it. It exports a generic XML file.

 
Flag Post

I’ve been thinking about this for a while. Unknown Guardian I would definitely like to copy your method as it seems like a very clean and compressed method but I do not know how. Can you lead me to the right direction to figure out how to convert lets say an array of integers from 1-20 each representing a specific tile into a byte array and use Base64 to compress it? I should be able to figure out the reverse process of decoding it from there.

[EDIT] Never mind this isn’t very hard at all. Found a good tutorial to teach it all to me: Here it is
Although converting my tile Array using this method did not seem very efficient due to the complex level problem.

 
Flag Post

What we did is make and editor that outputs a json, then make the game load the json and make a map out of it.

 
Flag Post
Originally posted by qwerberberber:

What we did is make and editor that outputs a json, then make the game load the json and make a map out of it.

What technique have you used to show game elements in the editor and linking it to the game?
Let’s say you wanted to add a new enemy or property, have you used a drag-and-drop editor or something different?