Jump to content
  • Advertisement
Sign in to follow this  
NDraskovic

XML in XNA 4.0

This topic is 2527 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

Hey

I was wondering if it's possible to load the value of a variable used in a XNA 4.0 game from an XML file. In my game I have some events that I want to enable/disable depending on the level of the game. My idea is to wrap them into if-else statements where the condition of that statement is a simple bool variable - and that bool variable would get its value from the XML file. I think that by doing this I will make my game more flexible then it would be if I hard coded everything - I can define new levels just by adding a new XML file (since there is a limited number of events that can be influenced, all XML files would have the same schema, they would differ only in the values that are stored in different files). Is this possible, and if it is can you give me some links that might help me? I already read Shawn Hargreaves blog on the matter but it didn't help me much. Also if you have some other idea on how I can solve this problem please advise.
Thanks

Share this post


Link to post
Share on other sites
Advertisement

Hey

I was wondering if it's possible to load the value of a variable used in a XNA 4.0 game from an XML file. In my game I have some events that I want to enable/disable depending on the level of the game. My idea is to wrap them into if-else statements where the condition of that statement is a simple bool variable - and that bool variable would get its value from the XML file. I think that by doing this I will make my game more flexible then it would be if I hard coded everything - I can define new levels just by adding a new XML file (since there is a limited number of events that can be influenced, all XML files would have the same schema, they would differ only in the values that are stored in different files). Is this possible, and if it is can you give me some links that might help me? I already read Shawn Hargreaves blog on the matter but it didn't help me much. Also if you have some other idea on how I can solve this problem please advise.
Thanks


Do you wish to disable events of certain objects in the levels? This is a bad idea make the events that can fire data driven so that if the data for the event isn't defined it won't fire.
Depending on which platform you are targetting you can get arround the XML problem in XNA by using the XML components from .NET, this however does require you to know where they are stored reletaive to the application. When using the .NET xml serialisers however you are circumventing the complete asset pipeline however.

Share this post


Link to post
Share on other sites

Do you wish to disable events of certain objects in the levels?

I have 5 "checkpoints" that trigger certain methods when an object passes in front of it. Every checkpoint has the same set of methods, and I want to be able to enable/disable some or all of these methods being triggered when an object passes in front of it. These methods don't use any data from the XML file, they are just actions that are being taken by the game itself.

Depending on which platform you are targetting

Since this is a part of a college project that I'm working on, PC is the only platform that I'm targeting.

I already posted this question (as a subquestion of another problem that I managed to solve) in the DirectX and XNA forum, but it keeps getting ignored, so if you could take a look at it, I gave a much more detailed description of my problem, so you might get a better idea of what I need to do (here is the address of that question).
Thanks again.

Share this post


Link to post
Share on other sites

[quote name='NightCreature83' timestamp='1326186545' post='4901230']
Do you wish to disable events of certain objects in the levels?

I have 5 "checkpoints" that trigger certain methods when an object passes in front of it. Every checkpoint has the same set of methods, and I want to be able to enable/disable some or all of these methods being triggered when an object passes in front of it. These methods don't use any data from the XML file, they are just actions that are being taken by the game itself.

Depending on which platform you are targetting

Since this is a part of a college project that I'm working on, PC is the only platform that I'm targeting.

I already posted this question (as a subquestion of another problem that I managed to solve) in the DirectX and XNA forum, but it keeps getting ignored, so if you could take a look at it, I gave a much more detailed description of my problem, so you might get a better idea of what I need to do (here is the address of that question).
Thanks again.
[/quote]
I think you might want to redesign the architecture of your processing nodes and start thinking about a Component based system. This way you can see the processing node as a entity on it's own, the components attached to this entity define which action are taken when the box stops in front of it. So to disable a processing node you would have an entity without any components attached to it.
The components attached to eacht processing node should be serialised in from data. This makes it easy to add new types of processing on the fly or change the order in which processing actions are done without having to recompile the code.

Share this post


Link to post
Share on other sites

This makes it easy to add new types of processing on the fly or change the order in which processing actions are done without having to recompile the code.

How would I apply these changes - some external file or what?

Can you just give me some links that might help me (how to implement components and serialization), I received some new assignments at work, so I don't have much time to google search it right now (I will eventually but if you can help me speed up the process that would be great). Anyway thanks for your help I'll try to make it work.

Share this post


Link to post
Share on other sites
A few links to descriptions of what and how component based systems work:
http://altdevblogada...i-a-retrospect/ this is a series of five posts about the game entity systems.
http://altdevblogada...-of-components/

If you are just working for windows you can easily step outside of the content pipeline and arent even restricted by the compact .NET framework, so you can just load any external file you want. Look at the XmlDocument documentation on MSDN, or define your own data file and write a loader for that.

Serialisation can be handled in many ways but usually the object that need to support it contain a serialise and deserialise functions which are called just after object creation. Often this object creation is handled from a data file which uses relfection to create the objects.

For example a data xml file and some code.

<xml>
<SimpleDeserialiseExample name="ObjectName" \>
</xml>



class SimpleDeserialiseExample
{
void deserialise(XmlNode node)
{
//Do your deserialisation here for this object instance.
}
}

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!