XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

How do you store your levels?

Last post 03-25-2008 12:57 AM by AdamTheOtaku. 5 replies.
  • 03-23-2008 12:20 PM

    How do you store your levels?

    I'm making a side scrolling shoot 'em up and I'm at the point now that I need to stop making the levels by hand and start making an editor but I don't know the best way to go about it.

    1. What storage format?

    I was thinking about writing a 2D editor and storing in XML but I don't know if that's the easiest/simplest way to do that. I've written 2D level editors before and it becomes a nightmare keeping my game and the editor in sync. I've also seen it done where people use integers to represent an enemy and just store an int[] and read that.

    2. What's the best way to keep the game and the editor in sync?

    Manually doing this almost killed the previous projects I worked on so there's got to be a dynamic way of doing but I dunno...

    Thanks in advance for any input you guys have...

  • 03-23-2008 3:58 PM In reply to

    Re: How do you store your levels?

    Answer
    What I did for my tile engine tutorials was to use a custom text-based format that was read it. It made file sizes smaller than XML and, in my opinion, made the file easier to work with. Basically the format was like this:

    [Textures]
    (list textures used here)

    [Properties]
    (additional properties here)

    [Layout]
    0 0 0 0 0 0
    0 0 0 0 0 0
    0 0 0 0 0 0

    (the layout grid indexes the textures listed at the top)


    To make the editor and game stay in sync, you want to share any code between them in a library project. So you solution should have three projects in it: 1) the game itself, 2) the editor app, and 3) the library containing all shared code. That way any changes to your core "engine" code will automatically affect both your editor and the game.
  • 03-23-2008 9:11 PM In reply to

    Re: How do you store your levels?

    That's similar to what I had in mind but what do you do when two things have the same texture but different behaviors? Like I have enemies that move in a sine wave and some that move in a straight line.
  • 03-24-2008 7:54 AM In reply to

    Re: How do you store your levels?

    AI isn't the kind of thing that's stored in a level file. Store the type of enemy, sure, but your code determines how that enemy moves and acts.
    Jim Perry - Microsoft XNA MVP
    Here's what I'm up to.
    If people spent a minute searching the forums and reading the FAQs before posting I'd be out of a job.
  • 03-24-2008 2:54 PM In reply to

    Re: How do you store your levels?

    Answer
    it becomes a nightmare keeping my game and the editor in sync


    The best way to avoid problems is to put your level data code in a project of its own, building an assembly ("library"). The editor and the game will then both use the same code to read/write the data.

    I would probably use some form of serialization to store and read back the data, if the data is sets of complex objects. If the data is only "tile used at this square," "entity placed at this square" and "behavior of entity at this square," then you can store three arrays of byte, where the value of the byte is an index into a tile array, an index into an entity array, and an index into a behavior array. You may want to also store the tile array, entity array and behavior array in the actual file, and make it so that the editor can create/configure those arrays.


    Jon Watte, Direct3D MVP kW X-port 3ds Max .X exporter kW Animation source code
  • 03-25-2008 12:57 AM In reply to

    Re: How do you store your levels?

    I think I have a good idea about how to go about this now. Thanks for the input.
Page 1 of 1 (6 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG