/// <summary> /// Zaktualizuj rozmiary i po³o¿enie wszystkich komponentów w zale¿noœci od zmieniaj¹cego siê rozmiaru okna. /// </summary> /// <param name="gameTime">czas trwania gry</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { Exit(); } UpdateBackground(Window.ClientBounds.Width, Window.ClientBounds.Height); if (ScreenType != ScreenType.Login && _mainMenu == null) { LoadRestSreens(); } if (Utils.User != null && Utils.User.IsMusic == false) { if (MediaPlayer.State != MediaState.Paused) { MediaPlayer.Pause(); } } else { if (MediaPlayer.State != MediaState.Playing) { MediaPlayer.Play(_song); } } switch (ScreenType) { case ScreenType.MainMenu: _mainMenu.Update(gameTime, Window.ClientBounds.Width, Window.ClientBounds.Height); break; case ScreenType.Settings: _settings.Update(gameTime, Window.ClientBounds.Width, Window.ClientBounds.Height); break; case ScreenType.Help: _help.Update(gameTime, Window.ClientBounds.Width, Window.ClientBounds.Height); break; case ScreenType.HighScores: _highScores.Update(gameTime, Window.ClientBounds.Width, Window.ClientBounds.Height); break; case ScreenType.Game: _game.Update(gameTime, Window.ClientBounds.Width, Window.ClientBounds.Height); break; case ScreenType.LoadGame: _loadGame.Update(gameTime, Window.ClientBounds.Width, Window.ClientBounds.Height); break; case ScreenType.Login: _login.Update(gameTime, Window.ClientBounds.Width, Window.ClientBounds.Height); break; } base.Update(gameTime); }
/// <summary> /// The base update loop calls update loops corresponding to the current game state /// </summary> /// <param name="gameTime">Provides a snapshot of timing values</param> protected override void Update(GameTime gameTime) { // Update the game time GameTime = gameTime; // Switch over the current state switch (State) { // Call the corresponding update functions for each menu case GameState.MainMenu: MainMenuScreen.Update(); break; case GameState.Instructions: InstructionsScreen.Update(); break; case GameState.ModeSelection: ModeSelectionScreen.Update(); break; // Game Modes case GameState.ClassicGameplay: // Create a new gameplay screen if it is null if (gameplayScreen == null) { gameplayScreen = new GameplayScreen(); } // Update the gameplay screen gameplayScreen.Update(); break; // The gameplay screens are identical and differ only in the EnemyManager (what enemies spawn) // and PlayerShip (how the player is controlled), meaning GameplayScreen can be used generically // in handling all operations regarding drawing and updating gameplay case GameState.FreeGameplay: if (gameplayScreen == null) { gameplayScreen = new GameplayScreen(); } gameplayScreen.Update(); break; } // Check to see if the game state is not in gameplay if (State != GameState.ClassicGameplay && State != GameState.FreeGameplay) { // Set the gameplay screen to null since the player ship controls and enemies are agnostic // to the current scene. The gameplay screen prevents updates to the player and enemies but // will still draw them unless the gameplay screen is reset entirely gameplayScreen = null; } // Update the root update loop base.Update(gameTime); }
protected override void Update(GameTime gameTime) { //第四步 //time += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); //if (time >= 0.5f && !beginApply) //{ // beginApply = true; // if (Platform.PlatFormType == PlatFormType.UWP) // { // Session.ChangeDisplay(true); // Platform.GraphicsApplyChanges(); // } //} base.Update(gameTime); if (base.IsActive || Session.GlobalVariables.RunWhileNotFocused) { if (Platform.Current.InputTextNow()) { return; } InputManager.Update(Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds)); if (loadingScreen == null) { if (mainGameScreen == null) { if (mainMenuScreen == null) { } else { mainMenuScreen.Update(gameTime); } } else { if (isDebug) { mainGameScreen.Update(gameTime); } else { if (String.IsNullOrEmpty(err)) { #if DEBUG mainGameScreen.Update(gameTime); #else try { mainGameScreen.Update(gameTime); } catch (Exception ex) { err = "不好意思,游戏运行出错,点击将返回主菜单,请考虑读取自动存档。\r\n" + ex.Message; WebTools.TakeWarnMsg("mainGameScreen.Update", "", ex); } #endif } else { if (InputManager.IsPressed) { err = ""; //保存當前進度 mainGameScreen.SaveGameAutoPosition(); loadingScreen = new LoadingScreen(); loadingScreen.LoadScreenEvent += (sender0, e0) => { Platform.Sleep(1000); }; } } } } } else { loadingScreen.Update(gameTime); } //if (AltComboPressed(this.mainGameScreen.KeyState, Microsoft.Xna.Framework.Input.Keys.F4)) //{ // this.TryToExit(); //} //if (AltComboPressed(this.mainGameScreen.KeyState, Microsoft.Xna.Framework.Input.Keys.Enter) && (this.mainGameScreen.PeekUndoneWork().Kind == UndoneWorkKind.None)) //{ // this.mainGameScreen.ToggleFullScreen(); //} //游戏设置中的全屏选项勾选后将多次调用这个方法,界面会闪来闪去 //只在初始化的时候全屏一次就好啦…… /*if ((Session.GlobalVariables.FullScreen && !this.mainGameScreen.IsFullScreen) || (!Session.GlobalVariables.FullScreen && this.mainGameScreen.IsFullScreen)) * { * this.mainGameScreen.ToggleFullScreen(); * }*/ } }