Using the Game State Management Sample

Today we will talk about the next step in my project “Odyssey” game series. We have already talked about why we need to design a game, and then I attempted to design my own game which I call “Odyssey”. Now that we know what we’re trying to build, it’s time to prepare our “workbench” with the tools we need! One of the coolest samples we have released is the Game State Management sample. This sample gives you a working template you can use to create game menus, options, pop up messages, etc. I will be using this sample in project “Odyssey” to handle all the menus and game options. Trust me, this is saving me a whole lot of time! Let’s see how this sample works.

So what does the Game State Management (GSM) sample do exactly? I am going to steal the description text from the sample page on creators.xna.com:

The sample implements a simple game flow with a main menu, an options screen, some actual gameplay, and a pause menu. It displays a loading screen in between the menus and gameplay, and uses a popup message box to confirm whether the user really wants to quit.

I am going to do even better! Here’s a video of what the sample actually looks like, it will give you a much clearer picture of how it works:

See how it works? The sample has all the boiler plate code required to give your game menus, options, pause screen, etc. You just need to figure out how to use it and where to place your game code as well as any customizations to the interface.

GSM Sample Code Structure

The sample is structured in a very object oriented way so that you can just plug into it and get up and running quickly. To start things off, here’s the class diagram of the sample (Click on it to see the full thing):

Class Diagram

Alright, keep this diagram opened in a window since we’ll refer to it quite often.

How does it work?

The basic principle behind the sample is that it manages screens. A screen is a renderable entity in your game. You break down your game into screens and let the ScreenManager manage them for you by bringing them into view and out based on what the player does. Best way to understand how the screens idea works is to go through a scenario step by step.

Let’s go through the scenario of the player booting up the game, they get a Menu screen that has a Play option. They click on that and they see a loading screen and then they see the actual game play. They play a bit and then they hit Esc to quit and are presented with a “Are you sure you want to quit?” message. They say Yes and the game quits back to the main menu. This would require you to break up your scenario into a bunch of screens like this:

So the flow would be:

Menu -> Play game -> Loading Game -> Game play -> Pause Game -> Quit Game option -> Confirm quit -> Back to main menu

The would break up to the following screens:

  • Main Menu Screen: This is the screen that renders the Menu. Here you would have all the code that draws the options, moves selections up and down, etc:

image

  • Loading Screen: This is the screen that renders while the game is loading it’s content. In the sample, it looks like this: (very creative as you can see)
  • image
  • Gameplay Screen: This is the screen that contains all your game play. So if this was say SpaceWar, this would be the screen where the ships fight each other for instance. In the sample, we see this screen:
  • image
  • Pause Screen: When you hit the Esc button, you get to the pause screen which is a screen that renders on top of another one (i.e. Popup). This means that unlike the other screens we saw so far, it doesn’t remove the previous screen but instead dims it and renders over it:
  • image
  • Quit Game Screen: This is the confirmation screen for when you choose the “Quit Game” option. Again, this is a popup screen that renders on top of all the other screens dimming them under it.
  • image

There you go! When you confirm that you do indeed want to quit the game, you go back to the Main Menu screen and you are back at square one :)

Looking at the source

Alright, so now that we somewhat understand how this whole screens thing works, let’s take a closer look at the code. First we’ll start with that layout of the code in source explorer:

image

As you can see, the code is split into two main folders, the ScreenManager and Screens.

ScreenManager folder contains the classes that are instrumental in how the template works:image

GameScreen.cs: This is the base GameScreen class that all your screens will inherit from.  The class has a lot of interesting methods and properties, let’s take a closer look at some of them:

  • bool isPopup: You want to set this to true if you want to have your screen be drawn on top of the current screen. Otherwise, it will be transitioned in as the previous screen is transitioned away. Screens like Pause, confirmation boxes, etc will want this to be true. Screens like the loading screen, game screen, etc will want it false.
  • Timespan transitionOnTime and transitionOffTime: This is how you can control how fast this screen will transition in and out. You want to set this using something like:

this.transitionOffTime = TimeSpan.FromSeconds(2);

  • ExitScreen(): This is the function you want to call when your screen is exiting. This will have it transition off the correct way and get removed from the list of screens to be managed.
  • LoadContent(): Override this function and add code to load any content you will be using in this screen. Do the same for UnloadContent() of course.
  • HandleInput(): You want to override this function in your class and do all the input handling here. Why not do it in the Update? Well, this function will be called when your screen is Active and is in focus. This way the right screen gets to handle the input at the right time.
  • Draw(): Override this function and add your rendering code.

InputState.cs: Helper for reading input from keyboard and gamepad. This class tracks both the imagecurrent and previous state of both input devices, and implements query properties for high level input actions such as “move up through the menu” or “pause the game”.

This class is really helpful and is the one that you should extend to handle your own input as well. The class exposes methods that translate the gamePad input to more appropriate game actions. For instance, things like IsMenuSelect method can be used in the Menu screen to detect if the user clicked on the A button or Enter key to make a selection. Here, check out how it is used in the code for the menus in the sample:

 

 

   1: public override void HandleInput(InputState input)
   2: {
   3:     // Move to the previous menu entry?
   4:     if (input.MenuUp)
   5:     {
   6:         selectedEntry–;
   7:  
   8:         if (selectedEntry < 0)
   9:             selectedEntry = menuEntries.Count - 1;
  10:     } 
  11: }

See how it is very easy to handle input in a meaningful to the game way? No need to do code that directly checks for the A button press, instead, it is wrapped in the InputState class and the action for Menu Select is defined as a check for the A button press. My game will extend this class to handle things like input.MoveShipLeft for instance. Read the source for InputState.cs to get a better idea for how it’s used. Very well commented.

ScreenManager.cs: Ahimage, we come to the mother of all classes! This class right here is the heart of how this sample works!  The screen manager is the component which manages one or more GameScreen instances. It maintains a stack of screens, calls their Update and Draw methods at the appropriate times, and automatically routes input to the topmost active screen (text shameless stolen directly from the source).

So how does it work? Simple. You create your GameScreen drived screens (Menu, game play, pause, etc) and use the AddScreen method to add them to the ScreenManager. The ScreenManager simply iterates over all the screens it had, calls update on each one, calls InputHandle to the top most one and finally renders them all with the top most one rendered last.

So if you add a GamePlay screen followed by a Pause screen and then a Quit Confirmation screen, you’ll get all three screens rendered with the top most one (Confirmation one) in “focus” and the only one handling the input. You RemoveScreen (which you do by calling the ExitScreen() method) the confirmation screen and the Pause screen is now the top most one and is receiving input.

See how it all works now? It’s a stack of screens that are basically layers. Top most layer gets input and the rest don’t. Brilliant!

Every GameScreen has a ScreenManager property on it pointing to the one and only ScreenManager that was created at the start of the game. This way you can add/remove screens to it from any screen in the game.

Tip: Notice the SpriteBatch property on the ScreenManager? That is put there for convenience. Makes is easy to share one SpriteBatch across your game. You won’t need to create a new one in your screen to draw something. Just use this one instead!

 

Now we move on to the Screens folder to see what’s in there. imageThis folder contains the actual implementation of the sample around the template mechanics we discussed above. As you can see, there are a few screens here. There are a few that are specially interesting to us:

  • GamePlayScreen.cs: This is the screen that the sample uses to render the “game play” portion. So if you want to instantly use this sample for your game, just move your game code in this file and hook it up appropriately. It will just work and all you need to do is customize the menus and stuff and you’re done!
  • LoadingScreen.cs: Alright, this one is very important and needs you to pay attention to how it works because it’s a bit different than the others. The purpose of the LoadingScreen is to handle transitions between the game and the menu system. That does not include the menus that popup during the game play though. Let me explain further. When you start the sample, you start by adding a Background screen and then a Main Menu screen. Once you are ready to start the game, you technically can just add the GamePlay screen to the ScreenManager and it will work. But this will mean that you will have both the background and menu screens sitting in memory for no reason. So instead, you use the LoadingScreen as follows:

LoadingScreen.Load(ScreenManager, true, new GameplayScreen());

What this will do is the following: It will first clear all the screens that are in the ScreenManager because we don’t need to worry about them anymore. It then will render a Loading screen image as the GamePlayScreen is loading its content. You don’t have to do anything special for that. The Loading screen will keep the Loading text or image you specify up on the screen until your content is loaded. Very nifty. If your GamePlayScreen’s content loading is very fast, you can disable the rendering of a Loading text by setting the second argument in the Load method to false.

Now, once your game is ready to go back to the main menu screen, you will realize that that screen is no longer there! We cleared it when we loaded the game. So to go back to that screen, the sample uses the LoadingScreen again to transition us back to the Menu system like this:

LoadingScreen.Load(ScreenManager, false, new BackgroundScreen(),
                                                                     new MainMenuScreen());

See how that worked? We are telling the LoadingScreen to clear the current ScreenManager (it does that in the Load method) and then load it up with the BackgroundScreen followed by the MainMenuScreen. We use false for the second argument since we know that our MainMenuScreen loads pretty fast.

So as you can see, the LoadingScreen is instrumental as it sits in between your Main Menu and the game. You use it to transition from one to the other and back. You don’t have to use it and can just stack screens in the ScreenManager, but then if you have a particularly beefy Main Menu screen, you’ll have those resources in memory for no reason. Use it!

As for the rest of the classes up there, take a look at MessageBoxScreen for instance to see how it uses the this.isPopup = true to indicate that it is a pop up window that will not transition the ones below it.

Oh, you should check out MainMenuScreen.cs and OptionMenuScreen.cs to see how they use MenuEntry class to implement the actual menu items. It uses events to detect when a menu was clicked. It’s simple enough to understand from the code.

Final words and next steps

Phew! That was a loooong post eh? Sorry about that but I really felt like I needed to make sure that this sample is fully explained before we can proceed. I myself haven’t really used it in depth, so this was a good exercise for me too. Once you go through how it works and look at the code a little bit, it totally makes sense very quickly and becomes trivial to use. It is intimidating at first but hopefully my explanation will help remove that.

Going forward we’ll start thinking about how to implement and structure project “Odyssey” in preparation for the implementation phase! Looks like I will have to actually code up this game! Should be fun and educational too!

In the meantime, go ahead and download the game state sample now and start playing with it. Get a sample game or even a moving texture integrated in it (Tip: Put the code you already have in the GamePlayScreen.cs file for starters). You will learn to love this sample quickly.

Thanks for reading! I'd love to hear your thoughts, feel free to leave a comment below. Don't forget to subscribe to my RSS Feed!

37 Responses to “Using the Game State Management Sample”

  1. Catalin Zima Says:

    Great article.
    I also like the GameStateManagement Sample most. I’ve used it as a starting point for my last project and for my current one.

    This tutorial could be very usefull for some people.

    As a suggestion, take a look at the Networked Game State Management. It modifies the LoadingScreen, to make it multithreaded, so the screen doesn’t freeze while loading content. You could easily show your readers how to move that vesion of LoadingScreen to this code.

  2. Ultrahead Says:

    I agree (an async loading method for the content would also do the trick).

  3. nazeeh Says:

    Agreed. I’ll integrate that class from it and hopefully package up the whole thing as a template for you guys to download.

    Thanks for the feedback!

  4. nazeeh Says:

    Done! I added the loading class as requested and made the whole thing into a template. Read about it here: http://www.nazspace.com/wp/2008/02/11/template-game-state-management/

  5. biu Says:

    hi there..
    i am struggling on this samples and this is a great article~!
    thanks very much
    i would wanna ask if anyone have tried to insert 3D objects in the game play…
    as i have inserted a few 3D models in to the game, and i found it can be “look through” in a lower view of angle…i.e. the upper component of the 3D model should be blocked by the lower part…but yet it didn’t…
    those models work properly in a single “stand alone” game without using the game state sample…
    can anyone explain and solve this problem?
    thanks~!

  6. nazeeh Says:

    That sounds like render states not being set correctly. You probably want to set the DepthBuffer to be enabled by putting this line of code before you render the 3D object:

    this.graphicsDevice.RenderState.DepthBufferEnable = true;

    Let me know if that doesn’t work for you. We can work it out and figure out what is happening.

    If you have any other feedback on this article let me know. I really hope that it makes using the sample easy. It’s such a good sample I am hoping everyone would use it.

  7. biu Says:

    thanks~
    that’s the problem..i have solved it~
    thanks very much

  8. biu Says:

    there is sth i wanna ask which is out of this article..
    as i carry on on my project..i would like to implement a “cursor picking 3D objects” function for my game
    is there any useful and not complicated algorithm that can be used?
    thanks very much for your opinion~

  9. nazeeh Says:

    Easy question ;) We already have two samples that you can check out that tell you how to do that:

    http://creators.xna.com/Headlines/developmentaspx/archive/2007/01/01/Picking-Sample.aspx
    and
    http://creators.xna.com/Headlines/developmentaspx/archive/2007/01/01/Picking-with-Triangle_2D00_Accuracy.aspx

    Have fun!

  10. biu Says:

    thanks~
    actually i have already tried the picking with triangle accuracy
    but i find it really difficult to understand the “pipeline” section…(even in some other samples with pipeline project…)
    i can’t get what’s going on and i easily got frustrated and finally reject to use it….(it is difficult for me to use “black box” algorithm…)
    so is there any guideline article on the samples?
    or other algorithm does not need to deal with the pipeline?….
    thanks very much~!

  11. nazeeh Says:

    Yes… the Content Pipeline can be a little tricky :) I will start talking about it soon though, so keep an eye out!

  12. biu Says:

    thanks~!
    i am looking forward to your articles~
    hope it will be very soon@@
    as i am stucked and time remaining for my project keeps decreasing..
    thanks ~

  13. Kris Athi Says:

    Hey Dude!

    Great article! everything is explained really well and it’s very easy to follow :)
    I do have a quick question though, to move a game already written into this template, the gameplay code needs moving into GamePlayScreen class…but where I’m a bit lost is where to put the initialisation code as this method is not present on the GamePlayScreen class

    Any help would be great!

    Kris

  14. nazeeh Says:

    Good question. I had a look at the code and I will double check this with the dev that wrote this sample. But what I would do probably would be to extend this to add an Initialize method to the base GameScreen class so that all my game screens can overload it. Then I would modify ScreenManager.cs and change the AddScreen to call screen.Initialize right before the call to screen.LoadContent.

    This should do it :) I will get back to you with the answer I get from the dude that wrote the sample as well.

  15. Shawn Hargreaves Says:

    Adding an Initialize method will work, but you could also just put all your initialization code into the constructor.

    The main Game class needs a separate Initialize that happens after the constructor, because things need to happen in a very particular order when the program first starts up. First the constructor registers whatever components it wants to use and specifies what graphics settings it wants, then the framework creates the graphics device using those settings, and then Initialize gives you a chance to set things up after the graphics device has been created.

    In this case, though, the graphics device has already been created even before the first menu screen came up, so none of those ordering requirements are a concern. That means there is no need to separate initialization behavior from object construction, so you might as well just use the constructor directly.

  16. Robert Says:

    Excellent writeup.. I feel like I actually understand what I’m doing now! :)

  17. Dave Says:

    Thanks for the post. I have a better understanding of how this works. I have one question though, in Shawn’s
    post he says the graphics device “has been already created even before the first menu screen came up” why is it that when I reference ‘graphics’ in my game logic I get an exception that “the name ‘graphics’ does not exist in current context. What I tried after that is, in my fields I added, GraphicsDeviceManager graphics, and in the constructor ( which is also where I put all code that was in Initialize().)
    if(graphics == null)
    {graphics = new GraphicsDeviceManager(ScreenManager.Game);}
    Any help would be greatly appreciated.

  18. nazeeh Says:

    hmm…how exactly are you referencing it in your code?

    and thanks for your comment about the post! :)

  19. Dave Says:

    I reference it when I’m doing things such as drawing and initializing vertices. An example is would be
    graphics.GraphicsDevice.VertexDeclaration = mVertPosColorTex;
    graphics.GraphicsDevice.DrawUserPrimitives(
    PrimitiveType.TriangleStrip, mVertSkybox, 0, 2);
    Anytime I used the graphics name before I added the if statement and I would get an exception for every instance I used it. After the if statement was added the menu now loads and I choose play game and it throws me a
    “Object reference not set to an instance of an object.” exception.
    thanks for the fast reply!

  20. nazeeh Says:

    hmm…wat I do - and works for me - is to use ScreenManager.Game.GraphicsDevice. Is that null for you?

  21. Dave Says:

    Yeah, it was null. I’ve made the changes from graphics.GraphicsDevice to ScreenManager.GraphicsDevice, and that works . But what is null now is content. The line
    mfx = content.Load(”.\\shaders\\BasicShader”);
    gets the same exception as ‘graphics’ did prior. I’ve tried replacing ‘content’ with ScreenManager.Content and it doesn’t work either. if you have the time to look through it I posted my GameplayScreen.cs here, http://pastebin.com/m73accbe0. Some things to note is theres another class that handles the camera called CCamera.cs and I have a two shaders BasicShader.fx and TextureShader.fx. This has been driving me nuts.

  22. montolio Says:

    hi,

    ‘Every GameScreen has a ScreenManager property on it pointing to the one and only ScreenManager that was created at the start of the game. This way you can add/remove screens to it from any screen in the game.’

    so in game you instatiate a ScreenManager, and in GameScreen there is a field for ScreenManager, but what i do not see is how you connect the field in GameScreen to the one that’s instantiated in Game.
    cuz i instantiated a audioManager in Game, and i want to acces that audioManager, so i added the property audioManager to GameScreen just like with ScreenManager. but that doesn’t work. so how do i couple these?

    any help would be appreciated.

  23. nazeeh Says:

    Hi Montolio,

    Alright, it’s pretty easy. Check out the file ScreenManager.cs, specifically the AddScreen(GameScreen screen) method. You’ll see that when you add a screen to the ScreenManager, it calls this:

    screen.ScreenManager = this;

    This is where it attaches a ScreenManager to a GameplayScreen. It’s done here since every gamescreen you use, you usually instantiate it, then add it to the ScreenManager. So during the Add process, the screenmanager attaches itself to it.

    So to add your AudioManager, this might be a place to add it too. Create an instance of your AudioManager and make sure it exists in the ScreenManager, and just attach it to every screen the same way.

    Let me know if you have more questions. :)

  24. Chris Says:

    Hello,

    I am trying to split the code into Engine/Demo setting.

    I keep getting access errors because of protection levels. I know what the problem is, and I know one way to fix it, the problem is that then I lose my concept of having a Engine/Demo setting, were you can just add any screens in the Demo, and never have to look at the Engine code.

    It would take rather long to lay this out here, so I have attached my solutions here below.
    http://www.noremorse.ca/Wars%20of%20Ardara.rar

    Any suggestions you can post here or email to chrisciscoioio At gmail Dot com

    any help would be great,

    Thanks

  25. J Says:

    hey guys im having a problem i hope someone can help me. I am using this screen transition example with some game code that i had already made. It works fine on its own but when i use it with this example (which is really nice btw) i get a content load exception “error loading file not found” for one of my fbx files in the loadcontent method of gameplay screen. i think it has something to do with the fact that in the game class i have
    graphics = new GraphicsDeviceManager(this);
    Content.RootDirectory = “Content”;

    and then
    content = new ContentManager(ScreenManager.Game.Services, “Content”);
    in the load content method of my Gameplayscreen. Somehow they arent jiving. Having said that i dont really know what is going wrong except to say i have looked at the obvious stuff (making sure i actually have the .fbx file and that). am i doing something incredibly stupid??

  26. nazeeh Says:

    Nah…not stupid :)

    The way the Content pipeline works is simple really. Let’s say you have your game in this layout:

    * Game.exe
    * Content (this is a folder)
    ====>model.fbx (under the content folder)

    To load model.fbx you need to specify the correct path to that file “relative” to game.exe. So in this case it would be “Content\model.fbx”

    So you can load it like this:

    model = Content.Load(”content/model”)

    In order to not keep putting “content/” before every asset, you can either initialize the ContentManager and give it “Content” as the Rootdirectory like in your code:

    content = new ContentManager(ScreenManager.Game.Services, “Content”);

    OR

    graphics = new GraphicsDeviceManager(this);
    Content.RootDirectory = “Content”;

    They are the same thing.

    Once you do that, you can just say:

    content.Load(”model”) and the content pipeline will know to put “content\” before “model” automatically.

  27. J Says:

    Thanks that solved my problem, i could have saved this bruise on my head LOL! Im having a problem with initializing my graphics content. I put a initialize method in the screenmanager class which i hoped to override in the gameplayscreen.
    public override void Initialize()
    {
    base.Initialize();

    isInitialized = true;
    }

    I then tried to override it like this

    public override void Initialize()
    {

    //lots of stuff in here

    base.Initialize();
    }
    in my gameplayscreen. The problem is it never gets to initialization in the gameplay screen. When it gets to the gameplayscreen draw method it crashes because i am using variables that in the draw method that are defined in a method that i call in the gameplayscreen initialization. So i get a “Object reference not set to an instance of an object.” My wall and head are feeling the effects :(

  28. nazeeh Says:

    You should sit far away from a wall dude ;)

    Alright…check out comment #14 and 15 on this thread. You’ll find your answer!

  29. J Says:

    thanks that did explain things. I am using a bullet array based on one of the tutorials, the whole program works on its own (with everyhting in game.cs) but when i put it into the gameplay screen i get an “object reference not set to an instance of an object” error in

    if (ship.isActive)
    {
    // Draw all the active bullets on screen
    for (int k = 0; k < GameConstants.NumBullets; k++)
    {
    if (bulletList[k].isActive)
    {
    Matrix bulletTransform =
    Matrix.CreateTranslation(bulletList[k].position);
    DrawModel(bulletModel, bulletTransform, bulletTransforms);

    }
    }

    }
    for the if (bulletList[k].isActive) part. but i have set it at the top with

    Bullet[] bulletList = new Bullet[GameConstants.NumBullets];

    the only real difference with my original game and this one is i put the i put the initialize stuff in the constructor and i didnt use UpdateInput method for the controls used the hanldeinput instead. If i take evrythhing to do with firing or bulletList out the game works fine, the badguys and the player are drawn onscreen so it is definatly to do with that.

    Model bulletModel;
    Matrix[] bulletTransforms;
    Bullet[] bulletList = new Bullet[GameConstants.NumBullets];
    is defined as follows. I hate to keep bothering you but this is the only place that get a useful answer to my questions.

  30. Ricardo Says:

    Regarding what mozolio said about audio, I solved that problem other way.

    In “GameScreen” class i added :
    public virtual void HandleCamera(FirstPersonCamera camera) { }

    So in this way i can override the method in a similar way we do with HandleInput, but for audio, so that in the class you want to manage your audio you simply call:

    public override void HandleSound(SoundManager sound)
    {
    sound.Play(”sound_file”);
    }

    Off course you need a “SoundManager” class that provides the “play” method, but normal tutorials for XNA audio usually show how to do it.

    This worked for me :), but could be better ways.

  31. Ricardo Says:

    IN my last post where i wrote “public virtual void HandleCamera(FirstPersonCamera camera) { }” IT SHOULD BE :

    “public virtual void HandleSound(SoundManager sound) { }”

    Sorry about that.

  32. Benzino Says:

    Hey, Great post, but im kinda struck.

    Alot of the game we are working on is nearly complete (or in advanced stages) and we are only now adding the game menu System. This is proving to me a total nightmare, with classes needed to be changed nearly everywhere (as we were accessing vars from the Game1 class). Anyway, we need access to the GraphicsDeviceManager, but the following code does not work:

    if(graphics == null)
    {
    graphics = new GraphicsDeviceManager(ScreenManager.Game);
    }

    Any Ideas?

  33. nazeeh Says:

    Where are you doing this? I am guessing you’re running this in a constructor of one of your Screens. If you are, then ScreenManager will be null at the time of construction. This is because the method that creates your screen first instantiates it THEN it assigns it a copy of ScreenManager.

    If you look in this post’s comments, someone asked a similar question. I told them how they can have an Initialize method added to Screens where they can put code like this. Then you would modify the method that creates screens and have it call the Init function after assigning a ScreenManager to the class.

  34. Benzino Says:

    Thanks for the reply and great post!

  35. javi Says:

    Hi nazeeh, I’m trying to access graphics.ToggleFullScreen(); or graphics.IsFullScreen from the GameplayScreen class, but can not define a new GraphicsDeviceManager this way:
    graphics = new GraphicsDeviceManager (this);

    I’m a little confused, i don’t know the exactly in which class I can introduce code so when you press a button changes between full-screen to window and vice versa.

  36. nazeeh Says:

    Hey Javi,

    I am not looking at the code right now, but every gameplay screen should have a ScreenManager instance in it. You should be able to either find a GraphicsDevice on that ScreenManager somewhere, or a Game instance which has a GraphicsDevice on it. Something like ScreenManager.Game.GraphicsDevice.ToggleFullscreen();

    Let me know if you still have issues and I’ll look at the code and give you a more accurate answer :)

  37. javi Says:

    Thanks for reply Nazeeh!,

    Unfortunately ToggleFullScreen() is a method from GraphicsDeviceManager (not from GraphicsDevice), and is not way call it from ScreenManager.Game (that I knows..)

    Finally I found a way to resolve this, in ScreenManager I have created a new attribute:
    public GraphicsDeviceManager graphics;

    And change constructor this way:
    public ScreenManager(Game game,GraphicsDeviceManager graphics) : base(game)
    {
    this.graphics = graphics;
    }

    To toggle full screen I call this in GameplayScreen: ScreenManager.graphics.ToggleFullScreen();
    I don’t know if is the best way, but it works!

Leave a Reply

The page's WebCounter count says that you are visitor number Visitor Counter by Digits
FireStats icon Powered by FireStats