0

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);
    }
TheQuantumBros
  • 308
  • 2
  • 4
  • 16

2 Answers2

0

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();
}
gunr2171
  • 10,315
  • 25
  • 52
  • 75
Cyral
  • 12,859
  • 5
  • 40
  • 78
0

You can use different approaches based on what you are expecting to get. If you want to have smooth fade-out effect, you can use the Color parameter to achieve transparency: mBatch.Draw(mTheQuantumBros2, new Rectangle(300, 150, mTheQuantumBros2.Width, mTheQuantumBros2.Height), new Color(new Vector4(1.0f, 1.0f, 1.0f, 1.0f - (currentTime / totalTime))));
currentTime holds your current time, and totalTime is the time when you want the image to fully disappear.

If you need to do this kinds of animations more than one time, I recommend you to create a Timer class, which can help you navigating your time spans easily.

RaZeR RawByte
  • 238
  • 1
  • 10