/// <summary> /// Allows each screen to run logic. /// </summary> public override void Update(GameTime gameTime) { // Read the keyboard and gamepad. input.Update(); // Make a copy of the master screen list, to avoid confusion if // the process of updating one screen adds or removes others // (or it happens on another thread) screensToUpdate.Clear(); foreach (GameScreenBase screen in screens) { screensToUpdate.Add(screen); } bool otherScreenHasFocus = !Game.IsActive; bool coveredByOtherScreen = false; // Loop as long as there are screens waiting to be updated. while (screensToUpdate.Count > 0) { // Pop the topmost screen off the waiting list. GameScreenBase screen = screensToUpdate[screensToUpdate.Count - 1]; screensToUpdate.RemoveAt(screensToUpdate.Count - 1); // Update the screen. screen.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); if (screen.ScreenState == ScreenState.TransitionOn || screen.ScreenState == ScreenState.Active) { // If this is the first active screen we came across, // give it a chance to handle input and update presence. if (!otherScreenHasFocus) { screen.HandleInput(input); screen.UpdatePresence(); // presence support otherScreenHasFocus = true; } // If this is an active non-popup, inform any subsequent // screens that they are covered by it. if (!screen.IsPopup) { coveredByOtherScreen = true; } } } // Print debug trace? if (traceEnabled) { TraceScreens(); } }
/// <summary> /// 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. /// </summary> public void RemoveScreen(GameScreenBase screen) { // If we have a graphics device, tell the screen to unload content. if ((graphicsDeviceService != null) && (graphicsDeviceService.GraphicsDevice != null)) { screen.UnloadContent(); } screens.Remove(screen); screensToUpdate.Remove(screen); }
/// <summary> /// Adds a new screen to the screen manager. /// </summary> public void AddScreen(GameScreenBase screen) { screen.ScreenManager = this; // If we have a graphics device, tell the screen to load content. if ((graphicsDeviceService != null) && (graphicsDeviceService.GraphicsDevice != null)) { screen.LoadContent(); } screens.Add(screen); }
/// <summary> /// 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. /// </summary> public void RemoveScreen( GameScreenBase screen ) { // If we have a graphics device, tell the screen to unload content. if ( ( graphicsDeviceService != null ) && ( graphicsDeviceService.GraphicsDevice != null ) ) { screen.UnloadContent(); } screens.Remove( screen ); screensToUpdate.Remove( screen ); }
/// <summary> /// Adds a new screen to the screen manager. /// </summary> public void AddScreen( GameScreenBase screen ) { screen.ScreenManager = this; // If we have a graphics device, tell the screen to load content. if ( ( graphicsDeviceService != null ) && ( graphicsDeviceService.GraphicsDevice != null ) ) { screen.LoadContent(); } screens.Add( screen ); }