/// <summary> /// Narysuj wszytskie elementy znajduj¹ce siê w aplikacji. W zaleznoœci od ustawionego okna wybierz odpowiedni /// Screen do rysowania /// </summary> /// <param name="gameTime">czas trwanie gry</param> protected override void Draw(GameTime gameTime) { IsMouseVisible = true; if (ScreenType != ScreenType.Login && _mainMenu == null) { LoadRestSreens(); } GraphicsDevice.Clear(Color.White); _spriteBatch.Begin(); _spriteBatch.Draw(_background, new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height), Color.White); _spriteBatch.End(); _planetEngine.Draw(_spriteBatch); if (Utils.User == null || Utils.User.IsAnimation) { _rocketeEngine.Draw(_spriteBatch); } switch (ScreenType) { case ScreenType.MainMenu: _mainMenu.Draw(_spriteBatch); break; case ScreenType.Settings: _settings.Draw(_spriteBatch); break; case ScreenType.Help: _help.Draw(_spriteBatch); break; case ScreenType.HighScores: _highScores.Draw(_spriteBatch); break; case ScreenType.Game: _game.Draw(_spriteBatch); break; case ScreenType.LoadGame: _loadGame.Draw(_spriteBatch); break; case ScreenType.Login: _login.Draw(_spriteBatch); break; } if (Utils.User == null || Utils.User.IsAnimation) { _starsEngine.Draw(_spriteBatch); } base.Draw(gameTime); }
static void DrawNeeded(int screen, MainMenuScreen MainMenu1, NewGameScreen NewGameMenu1) { switch (screen) { case 1: MainMenu1.Draw(); break; case 2: NewGameMenu1.Draw(); break; default: break; } }
/// <summary> /// The base draw loop handles drawing all draw loops corresponding to the current game state /// </summary> /// <param name="gameTime">Provides a snapshot of timing values</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); // Switch based on the current scene switch (State) { // Call each corresponding draw method case GameState.MainMenu: MainMenuScreen.Draw(spriteBatch); break; case GameState.Instructions: InstructionsScreen.Draw(spriteBatch); break; case GameState.ModeSelection: ModeSelectionScreen.Draw(spriteBatch); break; // If the gameplayScreen is not defined because the state updates asynchronously from // the update loop creating a new instance of gameplayScreen, ignore the current frame // and wait until the gameplayScreen is defined case GameState.ClassicGameplay: if (gameplayScreen != null) { gameplayScreen.Draw(spriteBatch); } break; case GameState.FreeGameplay: if (gameplayScreen != null) { gameplayScreen.Draw(spriteBatch); } break; } }
protected override void Draw(GameTime gameTime) { //第五步 if (Platform.PlatFormType == PlatFormType.Win || Platform.PlatFormType == PlatFormType.UWP || Platform.PlatFormType == PlatFormType.Android || Platform.PlatFormType == PlatFormType.Desktop) { if (takePicture == true) { try { if (screenshot == null || screenshot.GraphicsDevice == null) { screenshot = new RenderTarget2D(Platform.GraphicsDevice, Platform.GraphicsDevice.Viewport.Width, Platform.GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None); } Platform.GraphicsDevice.SetRenderTarget(screenshot); } #pragma warning disable CS0168 // The variable 'ex' is declared but never used catch (Exception ex) #pragma warning restore CS0168 // The variable 'ex' is declared but never used { //Log... } //takePicture = false; } } var spriteMode = mainGameScreen == null ? SpriteSortMode.Deferred : SpriteSortMode.BackToFront; if (disScale) //Platform.PlatFormType == PlatForm.iOS && isRetina) { if (mainGameScreen == null || loadingScreen != null) { SpriteBatch.Begin(spriteMode, BlendState.AlphaBlend, null, null, null, null, SpriteScale1); } else { SpriteBatch.Begin(spriteMode, BlendState.AlphaBlend, null, null, null, null, SpriteScale2); } } else { SpriteBatch.Begin(spriteMode, BlendState.AlphaBlend); } Platform.GraphicsDevice.Clear(Color.TransparentBlack); //this.graphics.GraphicsDevice.Clear(Color.TransparentBlack); if (loadingScreen == null) { if (mainGameScreen == null) { if (mainMenuScreen == null) { } else { mainMenuScreen.Draw(gameTime); } } else { if (isDebug) { mainGameScreen.Draw(gameTime); } else { if (String.IsNullOrEmpty(err)) { try { mainGameScreen.Draw(gameTime); } catch (Exception ex) { err = "不好意思,游戏运行出错,点击将返回主菜单,请考虑读取自动存档。\r\n" + ex.Message; WebTools.TakeWarnMsg("mainGameScreen.Draw", "", ex); } } else { if (!String.IsNullOrEmpty(err)) { CacheManager.DrawString(Session.Current.Font, err.SplitLineString(100), errPos, Color.Red, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); } if (InputManager.IsPressed) { err = ""; //保存當前進度 mainGameScreen.SaveGameAutoPosition(); loadingScreen = new LoadingScreen(); loadingScreen.LoadScreenEvent += (sender0, e0) => { Platform.Sleep(1000); }; } } } } } else { loadingScreen.Draw(gameTime); } //view = Platform.Current.MemoryUsage; //if (!String.IsNullOrEmpty(view)) //{ // CacheManager.DrawString(Session.Current.Font, "view:" + view.SplitLineString(100), errPos, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); //} //if (!String.IsNullOrEmpty(warn) && lastWarnTime != null && (DateTime.Now - (DateTime)lastWarnTime).TotalSeconds < 20) //{ // CacheManager.DrawString(Session.Current.Font, "Warn:" + warn, errPos, Color.Red, 0f, Vector2.Zero, 0.8f, SpriteEffects.None, 1f); //} ////if (!String.IsNullOrEmpty(err)) ////{ ////CacheManager.DrawString(LightAncient, "Err:" + err.SplitLineString(100).ProcessStar(), errPos, Color.Red, 0f, Vector2.Zero, 0.5f, SpriteEffects.None, 1f); ////} if (renderLast != null) { SpriteBatch.Draw(renderLast, Vector2.Zero, Color.White); } SpriteBatch.End(); if (takePicture == true && String.IsNullOrEmpty(err)) { takePicture = false; try { if (Platform.PlatFormType == PlatFormType.Win || Platform.PlatFormType == PlatFormType.UWP || Platform.PlatFormType == PlatFormType.Android || Platform.PlatFormType == PlatFormType.Desktop) // || Platform.PlatFormType == PlatForm.iOS) { if (screenshot != null) { byte[] shot = Platform.Current.ScreenShot(Platform.GraphicsDevice, screenshot); //Season.GraphicsDevice.SetRenderTarget(null); if (shot != null && shot.Length > 0) { var task = new PlatformTask(() => { }); task.OnStartFinish += (result) => { if (task.ParamArrayResultBytes != null && task.ParamArrayResultBytes.Length > 0) { Platform.Current.SaveUserFile(picture, task.ParamArrayResultBytes, null); } }; Platform.Current.ResizeImageFile(shot, 800, 480, false, task); } } //Task.Run(async () => await Season.Current.SaveUserFile(picture, shot)); //var task = new SeasonTask(() => //{ // screenshot = new RenderTarget2D(Season.GraphicsDevice, 800, 480, false, SurfaceFormat.Color, DepthFormat.None); //}); } } catch (Exception ex) { WebTools.TakeWarnMsg("游戏界面截屏失败:", "takePicture:", ex); } } base.Draw(gameTime); }