XNA XML Map Loading

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
shawk08033
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 3
Joined: Tue Apr 22, 2014 5:47 pm
Current Project: 2d xna rpg
Favorite Gaming Platforms: XBpx
Programming Language of Choice: C#
Location: Tallahasse, FL

XNA XML Map Loading

Post 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.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: XNA XML Map Loading

Post 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.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
shawk08033
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 3
Joined: Tue Apr 22, 2014 5:47 pm
Current Project: 2d xna rpg
Favorite Gaming Platforms: XBpx
Programming Language of Choice: C#
Location: Tallahasse, FL

Re: XNA XML Map Loading

Post 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>
User avatar
flsfr
ES Beta Backer
ES Beta Backer
Posts: 3
Joined: Wed Jul 10, 2013 6:40 pm
Favorite Gaming Platforms: GBA, PC, NES
Programming Language of Choice: C++
Location: Victoria BC, Canada
Contact:

Re: XNA XML Map Loading

Post 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.
A philosophical game developer.
Personal Website
shawk08033
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 3
Joined: Tue Apr 22, 2014 5:47 pm
Current Project: 2d xna rpg
Favorite Gaming Platforms: XBpx
Programming Language of Choice: C#
Location: Tallahasse, FL

Re: XNA XML Map Loading

Post by shawk08033 »

User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: XNA XML Map Loading

Post 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).
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Post Reply