Loading a new instance of a class through XML not working quite right
Posted
by
Thegluestickman
on Game Development
See other posts from Game Development
or by Thegluestickman
Published on 2012-06-08T13:42:21Z
Indexed on
2012/06/08
16:50 UTC
Read the original article
Hit count: 419
I'm having trouble with XML and XNA. I want to be able to load weapon settings through XML to make my weapons easier to make and to have less code in the actual project file. So I started out making a basic XML document, something to just assign variables with. But no matter what I changed it gave me a new error every time. The code below gives me a "XML element 'Tag' not found", I added and it started to say the variables weren't found.
What I wanted to do in the XML file as well, was load a texture for the file too. So I created a static class to hold my texture values, then in the Texture tag of my XML document I would set it to that instance too. I think that's were the problems are occuring because that's where the "XML element 'Tag' not found" error is pointing me too.
My XML document:
<XnaContent>
<Asset Type="ConversationEngine.Weapon">
<weaponStrength>0</weaponStrength>
<damageModifiers>0</damageModifiers>
<speed>0</speed>
<magicDefense>0</magicDefense>
<description>0</description>
<identifier>0</identifier>
<weaponTexture>LoadWeaponTextures.ironSword</weaponTexture>
</Asset>
</XnaContent>
My Class to load the weapon XML:
public static class LoadWeaponXML
{
static Weapon Weapons;
public static Weapon WeaponLoad(ContentManager content, int id)
{
Weapons = content.Load<Weapon>(@"Weapons/" + id);
return Weapons;
}
}
public static class LoadWeaponTextures
{
public static Texture2D ironSword;
public static void TextureLoad(ContentManager content)
{
ironSword = content.Load<Texture2D>("Sword");
}
}
I'm not entirely sure if you can load textures through XML, but any help would be greatly appreciated.
© Game Development or respective owner