Skip to main content
Renamed question
Link
Andrew Russell
  • 21.3k
  • 7
  • 58
  • 104

Loading a new instance of a class throughinstance from XML not working quite rightwith Texture2D

added 289 characters in body
Source Link

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 class Weapon
{
    public int weaponStrength;
    public int damageModifiers;
    public int speed;
    public int magicDefense;
    public string description;
    public string identifier;
    public Texture2D weaponTexture;
}

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.

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.

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 class Weapon
{
    public int weaponStrength;
    public int damageModifiers;
    public int speed;
    public int magicDefense;
    public string description;
    public string identifier;
    public Texture2D weaponTexture;
}

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.

Tweeted twitter.com/#!/StackGameDev/status/211134034397507585
added 7 characters in body
Source Link

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.

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>
 

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.

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.

Source Link
Loading