Exemplo n.º 1
0
        /// <summary>
        /// Allows each screen to run logic.
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Update(GameTime gameTime)
        {
            // Copy the master screen list to avoid confusion if the process of updating one screen adds or removes others
            screensToUpdate.Clear();

            foreach (GameScreen screen in screens)
            {
                screensToUpdate.Add(screen);
            }

            bool otherScreenHasFocus  = !Game.IsActive;
            bool coveredByOtherScreen = false;

            while (screensToUpdate.Count > 0)
            {
                // Pop the topmost screen off the waiting list
                GameScreen 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 screen is active or becoming active and has the focus, let it handle input
                    if (!otherScreenHasFocus)
                    {
                        screen.HandleInput();

                        // Since this screen now has the focus, other screens updated subsequently in this loop do not.
                        otherScreenHasFocus = true;
                    }

                    // If this is not a pop-up, inform any subsequent screens that they are covered by it
                    if (!screen.IsPopup)
                    {
                        coveredByOtherScreen = true;
                    }
                }
            }
        }