Search code examples
imagexnadisposing

XNA - How to make an image disappear after x seconds?


Sorry to bother everyone, I can't find any good tutorials on XNA so I just come here for help, so how do you make it wait before disposing?

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.Black);
        // TODO: Add your drawing code here
        mBatch.Begin();
        mBatch.Draw(mTheQuantumBros2, new Rectangle(300, 150, mTheQuantumBros2.Width, mTheQuantumBros2.Height), Color.White);
        //How to make it wait for 3 seconds before disposing?
        mBatch.Dispose();
        mBatch.End();
        base.Draw(gameTime);
    }

Solution

  • You can use elapsed time so after the application has been open for X seconds it will disapear

    if (gameTime.TotalGameTime.TotalSeconds <= 3)
    {
        mBatch.Begin();
        mBatch.Draw(mTheQuantumBros2, 
            new Rectangle(300, 150, mTheQuantumBros2.Width, mTheQuantumBros2.Height),
            Color.White);
        //How to make it wait for 3 seconds before disposing?
        mBatch.End();
    }