Si vous souhaitez disposer d'une texture, la meilleure façon de le faire:
SpriteBatch spriteBatch;
Texture2D texture;
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
texture = Content.Load<Texture2D>(@"Textures\Brick00");
}
protected override void Update(GameTime gameTime)
{
// Logic which disposes texture, it may be different.
if (Keyboard.GetState().IsKeyDown(Keys.D))
{
texture.Dispose();
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearWrap, DepthStencilState.None, RasterizerState.CullCounterClockwise, null);
// Here you should check, was it disposed.
if (!texture.IsDisposed)
spriteBatch.Draw(texture, new Vector2(resolution.Width/2, resolution.Height/2), null, Color.White, 0, Vector2.Zero, 0.25f, SpriteEffects.None, 0);
spriteBatch.End();
base.Draw(gameTime);
}
Si vous souhaitez disposer tout le contenu après la sortie du jeu, la meilleure façon de le faire:
protected override void UnloadContent()
{
Content.Unload();
}
Si vous souhaitez disposer la texture seulement après la sortie du jeu:
protected override void UnloadContent()
{
texture.Dispose();
}
double possible de [Comment XNAs Content.Load fonctionner?] (Http://stackoverflow.com/questions/4242741/how-does-xnas-content-loadtexture2d-operate) –