Пример #1
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            if (screenshotThisFrame)
            {
                GraphicsDevice.SetRenderTarget(screenshotTarget);
            }

            Matrix transform = Matrix.Identity;

            switch (gameState)
            {
            case GameState.PlayingLevel:
                GraphicsDevice.Clear(Arena.BackgroundColor);
                transform = Arena.ScreenTransform;
                break;

            case GameState.Menu:
                if (Desktop.Root == mainMenu)
                {
                    GraphicsDevice.Clear(MenuScene.BackgroundColor);
                }
                else
                {
                    GraphicsDevice.Clear(Color.White);
                }
                transform = menuScene.Camera.Transform;
                break;

            case GameState.LoadingScreen:
                GraphicsDevice.Clear(MenuScene.BackgroundColor);
                break;
            }

            spriteBatch.BeginWithMySettings(transform, null);
            drawBatch.BeginWithMySettings(transform, null);

            switch (gameState)
            {
            case GameState.LoadingScreen:
                break;

            case GameState.Menu:
                if (Desktop.Root == mainMenu)
                {
                    menuScene.Draw(spriteBatch, drawBatch);
                }
                DrawUI(transform);
                break;

            case GameState.PlayingLevel:
                Arena.Draw(GraphicsDevice, spriteBatch, drawBatch);
                DrawUI(transform);
                break;
            }

            drawBatch.End();
            spriteBatch.End();

            spriteBatch.Begin();
            fpsCounter.Update(gameTime);
            DrawFps();
            spriteBatch.End();

            if (screenshotThisFrame)
            {
                SaveScreenshot(screenshotTarget);
                screenshotThisFrame = false;
                GraphicsDevice.SetRenderTarget(null);
                spriteBatch.Begin();
                spriteBatch.Draw(screenshotTarget, Vector2.Zero, Color.White);
                spriteBatch.End();
            }

            base.Draw(gameTime);
        }