How to show an alert before Draw?

Before I draw anything on the screen I do a bunch of file loads. They are, of course, error trapped. But, I can’t throw an error message to the screen (it appears) before Draw(). I was trying to use MessageBox

 MessageBox.Show("General Staff Error", "Unable to load PlayState file.", new[] { "OK"});

But it doesn’t display. Is there a way to throw an error message to the screen before Draw()?

You will have to write to your game window using SpriteBatch.DrawString or use Debug.Write / Debug.WriteLine to the output, which is either the console or in Visual Studio.

That makes sense. Thanks!

You might want to consider states for your game. It sounds like you could have a Loading state and a Loaded state.

This can be as simple as…

protected override void Draw(GameTime gameTime)
  switch (m_state)
    case GameState.Loading:
      // Draw your messages here
    case GameState.Loaded:
      // Draw your normal stuff here

Or you can make it more complicated, with a class representing a scene and logic to manage transitions from one scene to another. Then you can have a Loading scene that runs until all your stuff is completed and has its own Draw method that shows the messages you want. Once loading is complete, it sets up a transition to a Running scene that does whatever you want there.

There’s a number of ways to solve this though, those are just some possibilities :slight_smile: