Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Mayday556   Members   -  Reputation: 111

Like
0Likes
Like

Posted 04 July 2014 - 02:26 PM

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?



Sponsor:

#2 Lactose!   GDNet+   -  Reputation: 3837

Like
1Likes
Like

Posted 04 July 2014 - 03:01 PM

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.



#3 Brian Sandberg   Members   -  Reputation: 1366

Like
1Likes
Like

Posted 04 July 2014 - 03:37 PM

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.



#4 BeerNutts   Crossbones+   -  Reputation: 3018

Like
1Likes
Like

Posted 05 July 2014 - 05:30 AM

google gleed2d for a map editor that isn't grid based, and uses xml to store the levels.


My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#5 Mayday556   Members   -  Reputation: 111

Like
0Likes
Like

Posted 06 July 2014 - 05:39 PM

Thanks a lot everyone, this really cleared things up for me!!!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS