I'm working on a 2D fighting game with XNA (C#). Everything was going well in my game until I added a story mode. There are more than 60 frames. I have a variable whose value changes each time the person presses the spacebar.
I wanted to experiment game state transitions and dispose() (or .Unload()) content when a screen was no longer needed. I have searched about Dispose() and Unload () to save memory that take my textures, but I can not give a value to my variable Texture2D after having called Dispose() for it. (texture.IsDisposed = true).
I have created a ContentManager xContent in a Manager Class.
Texture2D texture;
int image = 0;
____________________
if (Keyboard.GetState().IsKeyDown(Keys.Space))
{
if (image == 0)
{
texture = Manager.xContent.Load<Texture2D>("texture1");
}
else if (image == 1)
{
texture.Dispose();
texture = Manager.xContent.Load<Texture2D>("texture2");
}
}
Draw :
spriteBatch.Begin();
...
spriteBatch.End();
I received an error on spriteBatch.End() of the above paste because I have reloaded the texture. What should I do?