Public Group

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

## Recommended Posts

Hallo, Im working on a small top down game which uses a lot of tiles to represent the game world. I want to be able to load a map from a file so I looked into XML as it seams like a popular candidate. Does this format look ok?
<Game>
<Settings>
<screenHeigh = "800"/>
<screenWidth = "600"/>
</Settings>

<Level 1>
<Tile>
<fileLocation = "Data//tile_1.tga" xPos = "0" yPos = "0"/>
<fileLocation = "Data//tile_2.tga" xPos = "1" yPos = "2"/>
</Tile>

<CollisionBox>
<xPos = "10" yPos = "10" width = "5" height = "5"/>
<xPos = "15" yPos = "15" width = "5" height = "5"/>
</CollisionBox>

<Item>
<Gun = "mp5" xPos = "5" yPos = "5"/>
<Health = "50hp" xPos = "5" yPos = "6"/>
</Item>
</Level 1>
</Game>



##### Share on other sites
I wouldn't try to keep all your game's data in one big xml file, that'll just get unweildy pretty quickly. Game settings for example (like your screen width/height) are user configurable and so should probably be in their own file. Similarly I'd put each level in their own file and have a master xml list which defines their order and has a relative file path to the actual level xml so you can just load in a single level instead of having to parse all the levels just to get the next one.

##### Share on other sites
Ah, thats a very good idea. But is the syntax so far right?

##### Share on other sites
Quote:
 Original post by h3roAh, thats a very good idea. But is the syntax so far right?

It looks ok, but it really depends on what you want it to do. As a note, most people editing your xml files by hand would prefer that you use standard naming conventions, such as 'src' for the path to a file.

##### Share on other sites
Quote:
 Original post by OrangyTangI wouldn't try to keep all your game's data in one big xml file, that'll just get unweildy pretty quickly. Game settings for example (like your screen width/height) are user configurable and so should probably be in their own file. Similarly I'd put each level in their own file and have a master xml list which defines their order and has a relative file path to the actual level xml so you can just load in a single level instead of having to parse all the levels just to get the next one.

Maybe the world in this level is 800 tiles by 600 tiles? it doesn't look like a master data file to me. Having said that, if that is the resolution setting I would definitely put that somewhere else. And yes, definitely separate levels into their own xml files.

Looks awesome. Although you will need a large section for your tile data and change the way you're currently storing it. Look into the normal forms of databases for data integrity and stuff. I was making a game that sounds very similar to yours. The way I implemented this was to have tileset xml files which referenced the actual image files like so:

<tileset>     <image file="gfx/grass.png" id="0" /> (you could also have other flags in there if you needed them)     <image file="gfx/concrete.png" id="1" />     <etc. /></tileset>

Then in the map file I referenced the appropriate tileset and then just had a data section like:

<data tileset="grasslands.xml">1,1,0,1,2,45,2,3,4,1,0,5,1... etc.</data>

In the game I loaded the tileset in, then the map data. Too easy, and your files are smaller and the integrity and clarity of your data is assured.

##### Share on other sites
Might want to look up serialization. It will save you a bunch of hassles when outputting and reading your data. Let the data members write and read themselves instead of you worrying about the minor issues. It makes it easier also when you need to add more data in the future.

theTroll

##### Share on other sites
Also, using XML for actual level data is not the wisest choice. Look at this:

<fileLocation = "Data//tile_1.tga" xPos = "0" yPos = "0"/>

over half of that whole line is just metadata. While it makes your level files readable, it makes them much slower to read and parse. I would suggest you use XML for organization of your files (i.e. level list, tile list, maybe settings), but for the data itself use some other format. Either go with pure data separated by some value (i.e. "tile1;0;0;tile2;1;0;tile3 etc.") or save it in binary as opposed to characters.

##### Share on other sites
I don't believe that lines like:

<screenHeight = "800"/>

are valid XML, are they? You can't use the element name like an attribute name. You either need:

<screenHeight>800</screenHeight>

or

<screenHeight value="800"/>

Maybe I've just missed something and it's a shorthand for the former case, but I've never seen it before either way.

##### Share on other sites
Quote:
 Original post by superpigMaybe I've just missed something and it's a shorthand for the former case, but I've never seen it before either way.

It would make more sense as:
<screen Height="800" Width="600" />

Though portrait orientation FTW?

1. 1
2. 2
Rutin
23
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 23
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631766
• Total Posts
3002233
×