Any Tutorials how to use the ScreenManager? Navigating Screens? Popping up a menu?

Topics: Developer Forum
Nov 27, 2012 at 4:18 PM

In the Farseer Samples, there he uses a ScreenManager. But I can't see what functions he calls to make a screen active or something like that. Any tutorials you'll suggest that uses this Class? Thank you.

Coordinator
Nov 28, 2012 at 1:20 AM

The ScreenManager has a bottom up list of screen objects that are all active. You basically use ScreenManager.AddScreen() to put on a new 'layer'.

Say you have 3 screens:

1. Background screen
2. Game screen
3. Menu screen

You would like the background to be in the back, so you would create a BackgroundScreen class that draws a texture to the screen. It should inherit from GameScreen as it has all the necessary methods for drawing, updating and handling inputs.

Then you create your game screen that contains the actual game. It also inherits from the GameScreen class and uses the HandleInput method to handle the character and stuff like that.

Then you have the menu where you can choose options, exit or resume game.

You then simply add the screens one by one on top of each other. The reason we have a screensystem like this, is so that we can control what screen to update, depending whether it has something on top of it or not. Example: The game screen should not keep playing when the menu screen is overlapping it, and that is why you can check 'otherScreenHasFocus' and 'coveredByOtherScreen' booleans inside the Update() method from the GameScreen class.

Snoop around the code a bit and get familiar with it.

Nov 28, 2012 at 1:35 AM

Thank you GenBox for that overview how it works. I've played with the code yesterday too and tried adding new levels/screens.

But the thing I don't know right now is how to go to another screen. example, in your samples there is AdvancedDemo1 and when I'm in there I want to go to AdvancedDemo2. Can you please teach me the code to do it?