Page 1 of 1

XNA XML Map Loading

Posted: Thu Apr 24, 2014 2:30 pm
by shawk08033
I am making a 2d rpg game in xna and I need to be able to use xna's xml framework to load a map. I have a so called "map egine" which has a map class that has a layer array/list and a layer class that has a gameobject array/list.

If some could help me find away I can use xml to define the map, its layer, than the layers object, and lastly the object components(lua, player). I attached my source code here: https://mega.co.nz/#!OQ5BiSoC!UlOPiiSkk ... 3l1UgRynSI.

Re: XNA XML Map Loading

Posted: Thu Apr 24, 2014 6:16 pm
by dandymcgee
Assuming you're using the full .NET framework, you should have access to the XmlSerializer class. Check out the example on the MSDN page.

Re: XNA XML Map Loading

Posted: Thu Apr 24, 2014 6:56 pm
by shawk08033
I need to read an xml not write it. I know xna has an xml framework itself but I need to read a xml file like this:
<Map name="shity map">
<Layer number="0">
<Gameobject renderable="true" name="player" x="0: y="0">
<Component type="player" parent="player"></Component>
<Component type="lua" script="player.lua" parent="player"></Component>
</GameObject>
</Layer>
</Map>

Re: XNA XML Map Loading

Posted: Thu Apr 24, 2014 8:00 pm
by flsfr
Though I've never used XNA and I am not up to speed with the .NET framework I'll be glad to help. You can use one of the Deserialize methods from the "XmlSerializer" class to "read an xml."
http://msdn.microsoft.com/en-us/library ... alize.aspx

Instead of using the given example class, "OrderedItem", you could use your "Map" class. However, I have no real idea what your "Map" class and it's members look like as the link you posted shawk08033 doesn't work – make sure it's surrounded using the url tag.

Re: XNA XML Map Loading

Posted: Fri Apr 25, 2014 1:38 pm
by shawk08033

Re: XNA XML Map Loading

Posted: Fri Apr 25, 2014 8:33 pm
by dandymcgee
flsfr wrote:Though I've never used XNA and I am not up to speed with the .NET framework I'll be glad to help. You can use one of the Deserialize methods from the "XmlSerializer" class to "read an xml."
http://msdn.microsoft.com/en-us/library ... alize.aspx
Aye, assuming you have access to or are able to recreate the C# class(es). Otherwise you'd have to use an XmlReader to consume the data into your own object(s).