コード例 #1
0
        protected override void Draw(GameTime gameTime)
        {
            if (!_isWindowFocused)
            {
                return;
            }

            GraphicsDevice.Clear(_clearColor);
            var r = new RectangleF(32, 32, 196, 32);
            var c = r.Contains(new PointF(_previousMouseState.X, _previousMouseState.Y))
                ? _previousMouseState.LeftButton == ButtonState.Pressed
                    ? Color.OrangeRed
                    : Color.Yellow
                : Color.Peru;
            var t = r.Contains(new PointF(_previousMouseState.X, _previousMouseState.Y))
                ? 4.0f
                : 1.0f;

            _spriteBatch.Begin();
            _spriteBatch.DrawRectangle(r, c, t);
            _spriteBatch.End();

            _worldRenderer.Draw(GraphicsDevice, _currentWorld, _camera);

            _imGuiRenderer.BeginLayout(gameTime);
            DrawUserInterface(gameTime);

            ImGui.ShowDemoWindow();

            _windowProvider.Draw();
            _imGuiRenderer.EndLayout();

            base.Draw(gameTime);
        }
コード例 #2
0
ファイル: GameRenderer.cs プロジェクト: Rixium/Mayday
        public void Draw(
            Camera camera,
            IGameWorld gameWorld,
            IEntitySet entitySet,
            IEntity myPlayer,
            LightMap lightMap)
        {
            if (_renderTarget.Width != Window.WindowWidth)
            {
                _renderTarget = new RenderTarget2D(
                    Window.GraphicsDeviceManager.GraphicsDevice,
                    Window.WindowWidth, Window.WindowHeight);
            }

            if (lightMap.ChangedSinceLastGet)
            {
                _lightMapRenderer.RenderToRenderTarget(
                    camera,
                    myPlayer.GameArea,
                    lightMap);
            }

            Window.GraphicsDeviceManager.GraphicsDevice.SetRenderTarget(_renderTarget);

            GraphicsUtils.Instance.Begin();
            GraphicsUtils.Instance.SpriteBatch.Draw(ContentChest.Background, new Rectangle(0, 0, Window.WindowWidth, Window.WindowHeight), Color.White);
            GraphicsUtils.Instance.End();

            GraphicsUtils.Instance.Begin(camera.GetMatrix());
            _worldRenderer.DrawWorldObjects(gameWorld.GameAreas[0], camera);
            _playerRenderer.DrawPlayers(entitySet.GetAll());

            foreach (var entity in gameWorld.GameAreas[0].GetItems())
            {
                if (!_updateResolver.ShouldUpdate(entity))
                {
                    continue;
                }
                if (!(entity is ItemDrop item))
                {
                    continue;
                }
                GraphicsUtils.Instance.SpriteBatch.Draw(ContentChest.ItemTextures[item.Item.ItemId],
                                                        new Vector2(item.X, item.Y), Color.White);
            }

            _worldRenderer.Draw(gameWorld.GameAreas[0], camera);
            GraphicsUtils.Instance.End();

            GraphicsUtils.Instance.SpriteBatch.Begin(
                SpriteSortMode.Deferred,
                null,                // No blending
                null,                // Point clamp, so we get sexy pixel perfect resizing
                null,                // We don't care about this. Tbh, I don't even understand it.
                null,                // I don't even know what this it.
                null,                // We can choose to flip textures as an example, but we dont, so null it.
                camera.GetMatrix()); // Window viewport, for nice resizing.
            _lightMapRenderer?.Draw(camera, myPlayer, gameWorld);
            GraphicsUtils.Instance.End();

            Window.GraphicsDeviceManager.GraphicsDevice.SetRenderTarget(null);

            GraphicsUtils.Instance.SpriteBatch.Begin();
            GraphicsUtils.Instance.SpriteBatch.Draw(_renderTarget,
                                                    new Rectangle(0, 0, Window.WindowWidth, Window.WindowHeight), Color.White);
            GraphicsUtils.Instance.End();
        }