Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on a Pong clone in XNA. Gameplay-wise, I have it where I want it to be. I want to add a title screen and some other screens to it like a menu, as well as a screen for the Winning/Losing results.

I've tried the Game State Management Example on the App Hub site, but It's very complicated and I haven't been able to make sense of it. Is there a simpler way?

I'm hoping for a solution that can be used in other projects too.

Plus I'd like to know how to actually create menu items (basically, how do I display the different options on it, and highlight them, etc).

share|improve this question
Something about menu screen can be also found in XNA 3.0 Game programming recipes - - if you don't have the book, you can have at least code :) – zacharmarz Sep 19 '11 at 17:31
The game state management example is a really good way to do it. I'd recommend trying to get your head around it, worked a treat in our game. – Tristan Warner-Smith Sep 21 '11 at 10:26
Does anyone have the link to the Game State Management example on App Hub? – ashes999 Jan 27 '13 at 3:18

I'd recommend continuing to battle it out learning the sample. Once you groc how to implement it, you get all the nice things it does (screen fades, pause control, etc.) for nothing.

share|improve this answer
Microsoft doesn't really give much info on the code itself. Are there any other places that might? – Slateboard Sep 19 '11 at 16:06
Is there anything in particular that's proving troublesome? I found the player index stuff a little verbose, same with the transition stuff. In high level terms it's just a stack of Screens (which are simply classes with a Draw and Update method called by ScreenManager that can be added to / cleared by a call to Load in the ScreenManager. Load uses a 'params' argument so you can send it as many new screens as you want. ScreenManager stores Screens as a list and iterates over them on Update. – codinghands Apr 10 '12 at 10:29

I would seriously consider sticking it out with the game state management example. It is a great framework for your first game. If you were designing one that can be re-used, with menu items etc. you'd probably end up with something similar.

The basic idea is to have a stack of screens (GameScreen is the base screen class, The ScreenManager is the 'stack' manager in the sample i think).

i.e. start with a title screen. Pressing a button pushes the main menu screen onto the stack.

While any screen is transitioning on, render it as such (menu items can use the transition amount to decided where to render, so they appear to slide on-screen).

Always direct input to only the top screen, even while transitioning on (so fast menu selectors can easily get into the game while the menus are transitioning on).

Once the top screen is fully transitioned, only render that screen.

So during gameplay you could end up with the following on the screen stack:

TitleScreen, MainMenuScreen, GamePlayScreen, PauseMenuScreen.

In that state, the pause menu gets rendered, and that's the screen the player controls. To 'exit' the screen, simply pop it off of the stack (or start it transitioning off), then it's the gameplay screen that gets input and is rendered.

share|improve this answer

maybe this method not the best, but for pong game could be enough, and is easy to understand.

Make a enum with your states:

 enum States { Menu, Playing, Pause, Lost, Win, Intro }

In your update method:

 void Update(gameTime time)
     switch (State)
        case States.Intro: UpdateIntro(gametime); break;
        case States.Menu: UpdateMenu(gametime); break;
        case States.Playing: UpdatePlaying(gametime); break;

In your draw method is the same but with DrawMethods.

I'd recommend that the State variable is a property this way:

 States State { 
    get {return _state;} 
    set { 
      if (_state!=value) {
          OnStateChanged(_state, value);

 void OnStateChanged(States prev, States next)
      if (prev == States.Menu && next == States.Playing)
share|improve this answer

I'm using this example myself right now - I found it easiest to recreate the classes myself, then take chunks of code over a bit at a time to see exactly how each method / class communicates with the rest. Now I've got all the pieces in play and an understanding of what they're doing. It's really the best example of screen management out there.

share|improve this answer

Since it wasn't mentioned in the question (nor the answers) -- the original, and best Game State Management class can be downloaded and learned from here -

It's applicable in both XNA 4.0 and MonoGame 3.2, Enjoy.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.