Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
3  
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. –  bummzack Dec 13 '11 at 11:06
    
welcome to SE, take time to read gamedev.stackexchange.com/faq to get help –  Noob Game Developer Nov 14 '12 at 6:10

1 Answer 1

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);
 }
share|improve this answer
5  
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. –  David Gouveia Dec 13 '11 at 15:12
    
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... –  Alexander Galkin Dec 13 '11 at 19:06
    
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). –  David Gouveia Dec 14 '11 at 0:38

Your Answer

 
discard

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.