Exemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            Input.Update();

            ScreensToUpdate.Clear();
            foreach (Screen current in Screens)
            {
                ScreensToUpdate.Add(current);
            }

            bool OtherScreenHasFocus  = !base.Game.IsActive;
            bool CoveredByOtherScreen = false;

            while (ScreensToUpdate.Count > 0)
            {
                Screen screen = ScreensToUpdate[ScreensToUpdate.Count - 1];
                ScreensToUpdate.RemoveAt(ScreensToUpdate.Count - 1);
                screen.Update(gameTime, OtherScreenHasFocus, CoveredByOtherScreen, Input);

                if (screen.ScreenState == ScreenState.TransitionOn || screen.ScreenState == ScreenState.Active)
                {
                    if (!OtherScreenHasFocus)
                    {
                        OtherScreenHasFocus = true;
                    }
                    if (!screen.IsPopup)
                    {
                        CoveredByOtherScreen = true;
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (MediaPlayer.State != MediaState.Playing)
            {
                CurrentBackgroundSong++;
                if (CurrentBackgroundSong > BackgroundSongs.Count - 1)
                {
                    CurrentBackgroundSong = 0;
                }
                MediaPlayer.Play(BackgroundSongs[CurrentBackgroundSong]);
            }

            // Đọc Input
            Input.Update();

            ScreensToUpdate.Clear();

            foreach (GameScreen screen in Screens)
            {
                ScreensToUpdate.Add(screen);
            }

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

            while (ScreensToUpdate.Count > 0)
            {
                GameScreen screen = ScreensToUpdate[ScreensToUpdate.Count - 1];

                ScreensToUpdate.RemoveAt(ScreensToUpdate.Count - 1);

                screen.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

                if (screen.ScreenState == ScreenState.TransitionOn ||
                    screen.ScreenState == ScreenState.Active)
                {
                    if (!otherScreenHasFocus)
                    {
                        screen.HandleInput(Input);

                        otherScreenHasFocus = true;
                    }

                    if (!screen.IsPopup)
                    {
                        coveredByOtherScreen = true;
                    }
                }
            }

            base.Update(gameTime);
        }
Exemplo n.º 3
0
        public void Update(GameTime gameTime, IInputHandler input, bool otherWindowHasFocus)
        {
            //Make a copy of the master screen list, to avoid confusion if the process of updating one screen adds or removes others.
            ScreensToUpdate.Clear();

            //Update the top screen separate from all other screens.
            if (null != TopScreen)
            {
                TopScreen.Update(gameTime, false, false);
                input.HandleInput(TopScreen);
            }

            for (int i = 0; i < Screens.Count; i++)
            {
                ScreensToUpdate.Add(Screens[i]);
            }

            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.
                var screen = ScreensToUpdate[ScreensToUpdate.Count - 1];
                ScreensToUpdate.RemoveAt(ScreensToUpdate.Count - 1);

                // Update the screen.
                screen.Update(gameTime, otherWindowHasFocus, coveredByOtherScreen);

                //If the screen is active, let it check the input
                if (screen.IsActive)
                {
                    input.HandleInput(screen);

                    //If this is a covering screen, let other screens know they are covered.
                    if (screen.CoverOtherScreens)
                    {
                        coveredByOtherScreen = true;
                    }
                }
            }
        }