Jump to content
  • Advertisement
Sign in to follow this  
Mayday556

How To Save A Non-Grid-Based Level For A Game

This topic is 1472 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been wondering for a while now: "How does a level editor save a level to be loaded up again?" and after searching around on the internet, I found that there are a few ways to do this. 1) Save the Level as a bunch of text, where 1 letter is a different block than another or 2) Save the Level as a bunch of pixels in an image where 1 pixel color is a different block than another pixel color.

 

Notice how both of these methods of saving rely on the level being grid-based. Well what about a level that isn't grid-based? There could be any number of objects, at any position possible! So, how does saving a complex level work?

Share this post


Link to post
Share on other sites
Advertisement

There are loads of ways of doing it.

How a level is saved will depend greatly on what specific things you need saved, and how the game will interpret them.

 

One way to solve your specific issue is to store a position and a rotation, either as some floats and some rotation angles or something, or by basically having the entire 4x4 matrix stored in the level's file.

Made-up example:

 

Object_Start

ObjectName = "MyObject"

ObjectType = "AwesomeObject"

ObjectPos = 100.023f, 39.5f, -882.0f

Object_End

 

Then, in this example when loading, the editor/game would see a new object block (from the "Object_Start" keyword), would assign its name and type based on the next keywords, and put it in the exact position you wanted it, based on the position data.

Share this post


Link to post
Share on other sites

Like Lactose wrote, there are loads of ways of doing it.  It'd probably be best for you to start out using some standard format like XML or JSON, instead of inventing your own text or binary format.  Then you'd have a file like

 

<map>

  <object id="MyObject">

   <type class="MyAwesomeObject" />

    <position x="100.023" y="39.5" z="-882" />

    <rotation z="23" />

  </object>

  ...

</map>

 

or

 

[

  {

     id: "MyObject",

     type: {

        class: "MyAwesomeObject"

     },

     position: {

       x: 100.023,

       y: 29.5,

       z: -882

     },

    rotation: {

      z: 23

    }

  }

  ...

]

 

Your language of choice will most likely an API for easily serializing/deserializing objects to text like this.

 

Depending on the size of your level, you can either keep it in memory as a flat list of objects like this, or you might need a spatial partitioning datastructure, like a simple 2d array or a quadtree, to contain the objects, so you dont have to traverse them all in order to touch the objects in a smaller area.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!