/// <summary> /// Replaces the current topmost screen with the one provided, removing the previous one from the internal screens stack. This does not call LoadContent() or UnloadContent() on either screen; use this to store a screen in "standby" for returning to later. /// </summary> /// <param name="screen">The new screen to add. It must not already be in the screens stack.</param> /// <param name="previousScreen">If successful, this will contain the previous topmost screen (or null if there was no screens).</param> /// <returns>True if the swap was successful.</returns> public bool SwapScreen(GameScreen screen, out GameScreen previousScreen) { previousScreen = null; //if the new screen is invalid, return false; if (screen == null || screens.Contains(screen)) return false; //remove and store old screen if (screens.Count > 0) { previousScreen = screens[screens.Count - 1]; previousScreen.Removed(); screens.RemoveAt(screens.Count - 1); screensToUpdate.Remove(previousScreen); } //push new one screens.Add(screen); screen.Added(); return true; }
/// <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(GameScreen screen) { if (screen == null || !screens.Contains(screen)) screen.Removed(); // If we have a graphics device, tell the screen to unload content. if (isInitialized) screen.UnloadContent(); screens.Remove(screen); screensToUpdate.Remove(screen); }