I have written a class to load an XML file but I always get this error message:
ArgumentNullException was unhandled
This method does not accept null for this parameter.
Parameter name: texture
I get the error message in the batch.Draw():
public void Draw(SpriteBatch batch)
{
batch.Draw(
texture,
position,
null,
Color.White,
rotation,
Vector2.Zero,
scale,
SpriteEffects.None,
0f);
}
What is wrong in the Sprite class?
I uploaded my project here: http://depositfiles.com/files/kj4an4ef7
The problem is that, like the error says, the variable
texturein theSpritedrawing code is null.The cause of the problem is: you call the
Load()method to load the list of sprites from the XML file, but that won’t reconstruct theTextureproperty of theSpriteclass. Thus, to fix your error, for each sprite you should call theLoad()too.That means, in the
LoadContent()method of theGame1class, after thesprites = Content.Load<List<Sprite>>("Levelinf");line, do something like this:Now, each sprite will have it’s texture loaded.
PS: this is more like a C# /XNA problem rather than a XML one 🙂