-4
\$\begingroup\$

I am creating a game using Visual Studio and trying to add the game state management example. I have added all the files from the example into my game but need to add in something to make it run the menu before the game starts. Any ideas on what I need to add, I've hit a blank.

\$\endgroup\$
2
  • 3
    \$\begingroup\$ Hi and welcome to gamedev. You should be more specific about what "game state management example" you're referring to. Also you're not really clear about what the problem is. \$\endgroup\$
    – bummzack
    Commented Dec 13, 2011 at 11:06
  • \$\begingroup\$ welcome to SE, take time to read gamedev.stackexchange.com/faq to get help \$\endgroup\$ Commented Nov 14, 2012 at 6:10

1 Answer 1

2
\$\begingroup\$

I'm going to go out on a limb, and guess that you are trying to implement the following:

http://create.msdn.com/en-US/education/catalog/sample/game_state_management

The code should be self-explanatory, but the main idea is that you need to initialize a ScreenManager object in your main game class in order to be able to use the system. Take a look at the code below, and make sure you have something similar set up.

 ScreenManager screenManager;
 protected override void LoadContent()
 {
       screenManager = new ScreenManager(this);
       Components.Add(screenManager);
       screenManager.AddScreen(new BackgroundScreen(), null);
       screenManager.AddScreen(new MainMenuScreen(), null);
 }
\$\endgroup\$
3
  • 5
    \$\begingroup\$ This, except for one detail - you shouldn't call Initialize manually because the Game class already calls Initialize for you when you add a Component during the game execution. You'd be initializing the ScreenManager twice this way. \$\endgroup\$ Commented Dec 13, 2011 at 15:12
  • \$\begingroup\$ One also need to have the classes BackgroundScreen and MainMenuScreen implemented before writing this code -- just in case if somebody thinks that those are standard ones... \$\endgroup\$ Commented Dec 13, 2011 at 19:06
  • \$\begingroup\$ By the way, I might add that this doesn't need to happen inside LoadContent, since the ScreenManager does not rely on the GraphicsDevice being initialized. Therefore you could safely move this code up into the Game's constructor (which is how it's done on the sample). \$\endgroup\$ Commented Dec 14, 2011 at 0:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .