The screen manager is a 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. More...
Public Member Functions | |
| ScreenManager (Game game) | |
| Constructs a new screen manager component. | |
| override void | Initialize () |
| Initializes the screen manager component. | |
| override void | Update (GameTime gameTime) |
| Allows each screen to run logic. | |
| override void | Draw (GameTime gameTime) |
| Tells each screen to draw itself. | |
| void | AddTexture (string textureKey, string texturePath) |
| Adds a texture to the manager pool and loads if it has not been loaded yet. | |
| void | AddFont (string fontKey, string fontPath) |
| Adds a sprite font to the manager pool and loads if it has not been loaded yet. | |
| void | AddSound (string soundKey, string soundPath) |
| Adds a sound effect to the manager pool and loads if it has not been loaded yet. | |
| void | AddScreen (GameScreen screen, PlayerIndex?controllingPlayer) |
| Adds a new screen to the screen manager. | |
| void | RemoveScreen (GameScreen screen) |
| Removes a screen from the screen manager. You should normally use GameScreen.ExitScreen instead of calling this directly, so the screen can gradually transition off rather than just being instantly removed. | |
| GameScreen[] | GetScreens () |
| Expose an array holding all the screens. We return a copy rather than the real master list, because screens should only ever be added or removed using the AddScreen and RemoveScreen methods. | |
| void | FadeBackBufferToBlack (int alpha) |
| Helper draws a translucent black fullscreen sprite, used for fading screens in and out, and for darkening the background behind popups. | |
| void | SetVolume (string category, float volume) |
| Sets the audio volume for the category. | |
Protected Member Functions | |
| override void | LoadContent () |
| Load your graphics content. | |
| override void | UnloadContent () |
| Unload your graphics content. | |
Properties | |
| SpriteBatch | SpriteBatch [get] |
| Gets a default SpriteBatch shared by all the screens. This saves each screen having to bother creating their own local instance. | |
| PrimitiveBatch | PrimitiveBatch [get] |
| Gets a default PrimitiveBatch shared by all the screens. This saves each screen having to bother creating their own local instance. | |
| VideoPlayer | VideoPlayer [get] |
| Gets a default VideoPlayer shared by all the screens. This saves each screen having to bother creating their own local instance. | |
| Dictionary< string, Texture2D > | Textures [get] |
| Gets the texture cache. | |
| Dictionary< string, SpriteFont > | Fonts [get] |
| Gets the font cache. | |
| Dictionary< string, Model > | Models [get] |
| Gets the model cache. | |
| Dictionary< string, SoundEffect > | Sounds [get] |
| Gets the sound effects cache. | |
| SoundBank | SoundBank [get] |
| Gets the soundbank. | |
| bool | TraceEnabled [get, set] |
| If true, the manager prints out a list of all the screens each time it is updated. This can be useful for making sure everything is being added and removed at the right times. | |
The screen manager is a 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.
Definition at line 25 of file ScreenManager.cs.
| NewGamePhysics.StateManager.ScreenManager.ScreenManager | ( | Game | game | ) |
Constructs a new screen manager component.
Definition at line 193 of file ScreenManager.cs.
| void NewGamePhysics.StateManager.ScreenManager.AddFont | ( | string | fontKey, | |
| string | fontPath | |||
| ) |
Adds a sprite font to the manager pool and loads if it has not been loaded yet.
| fontKey | The reference key to use for the font. | |
| fontPath | The content loader path for the font. |
Definition at line 378 of file ScreenManager.cs.
| void NewGamePhysics.StateManager.ScreenManager.AddScreen | ( | GameScreen | screen, | |
| PlayerIndex? | controllingPlayer | |||
| ) |
Adds a new screen to the screen manager.
Definition at line 403 of file ScreenManager.cs.
00404 { 00405 screen.ControllingPlayer = controllingPlayer; 00406 screen.ScreenManager = this; 00407 screen.IsExiting = false; 00408 00409 // If we have a graphics device, tell the screen to load content. 00410 if (isInitialized) 00411 { 00412 screen.LoadContent(); 00413 } 00414 00415 screens.Add(screen); 00416 }
| void NewGamePhysics.StateManager.ScreenManager.AddSound | ( | string | soundKey, | |
| string | soundPath | |||
| ) |
Adds a sound effect to the manager pool and loads if it has not been loaded yet.
| soundKey | The reference key to use for the sound. | |
| fontPath | The content loader path for the sound. |
Definition at line 392 of file ScreenManager.cs.
| void NewGamePhysics.StateManager.ScreenManager.AddTexture | ( | string | textureKey, | |
| string | texturePath | |||
| ) |
Adds a texture to the manager pool and loads if it has not been loaded yet.
| textureKey | The reference key to use for the texture. | |
| texturePath | The content loader path for the texture. |
Definition at line 364 of file ScreenManager.cs.
| override void NewGamePhysics.StateManager.ScreenManager.Draw | ( | GameTime | gameTime | ) |
Tells each screen to draw itself.
Definition at line 341 of file ScreenManager.cs.
| void NewGamePhysics.StateManager.ScreenManager.FadeBackBufferToBlack | ( | int | alpha | ) |
Helper draws a translucent black fullscreen sprite, used for fading screens in and out, and for darkening the background behind popups.
Definition at line 450 of file ScreenManager.cs.
00451 { 00452 Viewport viewport = GraphicsDevice.Viewport; 00453 00454 spriteBatch.Begin(); 00455 00456 spriteBatch.Draw(this.Textures["blank"], 00457 new Rectangle(0, 0, viewport.Width, viewport.Height), 00458 new Color(0, 0, 0, (byte)alpha)); 00459 00460 spriteBatch.End(); 00461 }
| GameScreen [] NewGamePhysics.StateManager.ScreenManager.GetScreens | ( | ) |
Expose an array holding all the screens. We return a copy rather than the real master list, because screens should only ever be added or removed using the AddScreen and RemoveScreen methods.
Definition at line 441 of file ScreenManager.cs.
| override void NewGamePhysics.StateManager.ScreenManager.Initialize | ( | ) |
Initializes the screen manager component.
Definition at line 201 of file ScreenManager.cs.
00202 { 00203 base.Initialize(); 00204 00205 // Initialize audio objects. 00206 this.engine = new AudioEngine("Content\\Sounds\\audio.xgs"); 00207 this.soundBank = new SoundBank(engine, "Content\\Sounds\\Sound Bank.xsb"); 00208 this.waveBank = new WaveBank(engine, "Content\\Sounds\\Wave Bank.xwb"); 00209 00210 isInitialized = true; 00211 }
| override void NewGamePhysics.StateManager.ScreenManager.LoadContent | ( | ) | [protected] |
Load your graphics content.
Definition at line 216 of file ScreenManager.cs.
00217 { 00218 // Load content belonging to the screen manager. 00219 ContentManager content = Game.Content; 00220 this.spriteBatch = new SpriteBatch(GraphicsDevice); 00221 this.primitiveBatch = new PrimitiveBatch(GraphicsDevice); 00222 this.videoPlayer = new VideoPlayer(); 00223 00224 // Prepare caches 00225 this.textures = new Dictionary<string, Texture2D>(); 00226 this.fonts = new Dictionary<string, SpriteFont>(); 00227 this.models = new Dictionary<string, Model>(); 00228 this.sounds = new Dictionary<string, SoundEffect>(); 00229 00230 // Prep font cache 00231 this.fonts.Add("menu", content.Load<SpriteFont>(@"Fonts\menufont")); 00232 this.fonts.Add("game", content.Load<SpriteFont>(@"Fonts\gamefont")); 00233 this.fonts.Add("small", content.Load<SpriteFont>(@"Fonts\smallfont")); 00234 00235 // Prep texture cache 00236 this.textures.Add("blank",content.Load<Texture2D>(@"Sprites\blank")); 00237 00238 // Tell each of the screens to load their content. 00239 foreach (GameScreen screen in screens) 00240 { 00241 screen.LoadContent(); 00242 } 00243 }
| void NewGamePhysics.StateManager.ScreenManager.RemoveScreen | ( | GameScreen | screen | ) |
Removes a screen from the screen manager. You should normally use GameScreen.ExitScreen instead of calling this directly, so the screen can gradually transition off rather than just being instantly removed.
Definition at line 424 of file ScreenManager.cs.
| void NewGamePhysics.StateManager.ScreenManager.SetVolume | ( | string | category, | |
| float | volume | |||
| ) |
Sets the audio volume for the category.
| category | Friendly name of the audio cues. | |
| volume | The new volume. |
Definition at line 468 of file ScreenManager.cs.
| override void NewGamePhysics.StateManager.ScreenManager.UnloadContent | ( | ) | [protected] |
Unload your graphics content.
Definition at line 248 of file ScreenManager.cs.
| override void NewGamePhysics.StateManager.ScreenManager.Update | ( | GameTime | gameTime | ) |
Allows each screen to run logic.
Definition at line 264 of file ScreenManager.cs.
00265 { 00266 // Read the keyboard and gamepad. 00267 this.input.Update(); 00268 00269 // Update the sound engine 00270 this.engine.Update(); 00271 00272 // Make a copy of the master screen list, to avoid confusion if 00273 // the process of updating one screen adds or removes others. 00274 screensToUpdate.Clear(); 00275 00276 foreach (GameScreen screen in screens) 00277 { 00278 screensToUpdate.Add(screen); 00279 } 00280 00281 bool otherScreenHasFocus = !Game.IsActive; 00282 bool coveredByOtherScreen = false; 00283 00284 // Loop as long as there are screens waiting to be updated. 00285 while (screensToUpdate.Count > 0) 00286 { 00287 // Pop the topmost screen off the waiting list. 00288 GameScreen screen = screensToUpdate[screensToUpdate.Count - 1]; 00289 00290 screensToUpdate.RemoveAt(screensToUpdate.Count - 1); 00291 00292 // Update the screen. 00293 screen.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); 00294 00295 if (screen.ScreenState == ScreenState.TransitionOn || 00296 screen.ScreenState == ScreenState.Active) 00297 { 00298 // If this is the first active screen we came across, 00299 // give it a chance to handle input. 00300 if (!otherScreenHasFocus) 00301 { 00302 screen.HandleInput(input); 00303 00304 otherScreenHasFocus = true; 00305 } 00306 00307 // If this is an active non-popup, inform any subsequent 00308 // screens that they are covered by it. 00309 if (!screen.IsPopup) 00310 { 00311 coveredByOtherScreen = true; 00312 } 00313 } 00314 } 00315 00316 // Print debug trace? 00317 if (traceEnabled) 00318 { 00319 TraceScreens(); 00320 } 00321 }
Dictionary<string, SpriteFont> NewGamePhysics.StateManager.ScreenManager.Fonts [get] |
Gets the font cache.
Definition at line 147 of file ScreenManager.cs.
Dictionary<string, Model> NewGamePhysics.StateManager.ScreenManager.Models [get] |
Gets the model cache.
Definition at line 155 of file ScreenManager.cs.
PrimitiveBatch NewGamePhysics.StateManager.ScreenManager.PrimitiveBatch [get] |
Gets a default PrimitiveBatch shared by all the screens. This saves each screen having to bother creating their own local instance.
Definition at line 122 of file ScreenManager.cs.
SoundBank NewGamePhysics.StateManager.ScreenManager.SoundBank [get] |
Gets the soundbank.
Definition at line 171 of file ScreenManager.cs.
Dictionary<string, SoundEffect> NewGamePhysics.StateManager.ScreenManager.Sounds [get] |
Gets the sound effects cache.
Definition at line 163 of file ScreenManager.cs.
SpriteBatch NewGamePhysics.StateManager.ScreenManager.SpriteBatch [get] |
Gets a default SpriteBatch shared by all the screens. This saves each screen having to bother creating their own local instance.
Definition at line 113 of file ScreenManager.cs.
Dictionary<string, Texture2D> NewGamePhysics.StateManager.ScreenManager.Textures [get] |
Gets the texture cache.
Definition at line 139 of file ScreenManager.cs.
bool NewGamePhysics.StateManager.ScreenManager.TraceEnabled [get, set] |
If true, the manager prints out a list of all the screens each time it is updated. This can be useful for making sure everything is being added and removed at the right times.
Definition at line 181 of file ScreenManager.cs.
VideoPlayer NewGamePhysics.StateManager.ScreenManager.VideoPlayer [get] |
Gets a default VideoPlayer shared by all the screens. This saves each screen having to bother creating their own local instance.
Definition at line 131 of file ScreenManager.cs.
1.6.2