3

I created an introscreen with "Press Enter to start the game",(and exit) ofcourse exit is no problem but to let the game start its a bit harder. Any advice?

Jack
  • 89
  • 1
  • 2
  • 4
  • possible duplicate of [Very simple menu in XNA](http://stackoverflow.com/questions/3941418/very-simple-menu-in-xna) – bzlm Oct 17 '10 at 10:41

3 Answers3

2

The easiest way to do this would be to set up a State Machine. It would look really simple.

enum GameState 
{
TitleScreen = 0,
GameStarted,
GameEnded,
}

Something then in the Game1.cs, or wherever you're handling this button click, you can put a variable in you class to store the current game state that you are in.

GameState currentGameState = GameState.TitleScreen;

Then, before you do a draw or update on the actual game you coded, you can check the current game state

void Draw(GameTime time)
{
   if(currentGameState == GameStarted)
   {
       //Then handle the game drawing code here

   }
}

The update method would basically look the same

TheBinaryhood
  • 231
  • 2
  • 9
1

The system I use works well (for me)

Setup an interface called something like IContext. in this have void Draw() and void Update().

then in game have a public IContext called Context. you simply call context.update() and context.draw() in the supplied gameloop.

Then a menu screen simply has to implement IContext. You pass in a reference to your game object through its constructor which lets you change the context from any object you plug in.

So you plug in "menu" and in menu when you recive the Enter key you call up this.game.context = new level01();

Hope this makes sense.

Nick

udondan
  • 57,263
  • 20
  • 190
  • 175
Nick
  • 948
  • 2
  • 12
  • 24
1

As ninename says a state machine is the way to go here. I would however sugest that you look at this sample - http://create.msdn.com/en-US/education/catalog/sample/game_state_management - provided by microsoft rather than roling your own.
Very easy to implment and change whist covering prety much everything you could want to do, including input handling.

Stuart
  • 1,123
  • 8
  • 24