Sign in to follow this  

Gamestate Manager Tutorial

This topic is 1403 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, a year or two ago i was doing a Gamestate Manager Tutorial, I did it two or three times but it was a bit too complicated to fully understand. Now I want to go over it again but i cannot find it anywhere. I believe it was a official tutorial from MSDN or it just looked like it. at least it was based off this sample from MSDN.

 

I can come up with my own menu and state manager now but i am really interested in other methods and it would be nice to see what i did not understand back then.

Share this post


Link to post
Share on other sites
ah yes, I remember this fondly. I used this as the starting point for most of my xna games. I'll confess I've not used this for over two years but from what I recal it was a very good object oriented sample. The ScreenManager object held a list of GameScreen in a "stack" manner where the one on top was active (unless is was bein transitioned off and out of the list). Menu, gameplay, options screens extended/inherited from the GameScreen class. Edited by idleMartin

Share this post


Link to post
Share on other sites

Implementing it into your own projects and then making minor modifications to it is the best way to learn what's going on with this sample in my opinion.

Edited by frazchaudhry

Share this post


Link to post
Share on other sites

Other method you can use - and which I'm right now experimenting in Orbstinate, with success atm, is to use XNA's GameComponent and DrawableGameComponent classes.

 

Basically, you have to create a new class which will inherit either one of those two (difference is that DrawableGameComponent has public virtual void Draw(GameTime gametime) method in addition to Initialize(), LoadContent(), UnloadContent() and Update(GameTime) methods) and write all the relevant stuff inside. Then, you register the component when you need it, for example:

public class Game1 : Microsoft.XNA.Framework.Game
{
    // snip

        MainMenu main = new MainMenu(this);
        Components.Add(main);

    // snip
}

Game itself will take care of running all relevant methods of each component registered onto Game.Components list when required. So, it boils down to adding components to or removing components from the Components list, which isn't so much different from the Gamestate Manager example Microsoft provided (and which was my starting point as well).

For example, in my game, I'm usually running Main Menu, Options Menu or Game part itself as one component, with Sound Manager being separate component which runs whole time.

Share this post


Link to post
Share on other sites
Sign in to follow this