private void DrawSpritesWithBatcher2D() { _batcher.Begin(_viewMatrix, _projectionMatrix, effect: _effect); // ReSharper disable once ForCanBeConvertedToForeach for (var index = 0; index < _sprites.Length; index++) { var sprite = _sprites[index]; _batcher.DrawTexture(sprite.Texture, ref sprite.TransformMatrix, sprite.Color); } _batcher.End(); }
public void Draw(Batcher2D batcher) { SortControlsByInfo(); batcher.GraphicsDevice.Clear(Color.Transparent); batcher.Begin(); for (int i = _gumps.Count - 1; i >= 0; i--) { Control g = _gumps[i]; if (g.IsInitialized) { g.Draw(batcher, g.X, g.Y); } } GameCursor?.Draw(batcher); batcher.End(); }
public void Draw(Batcher2D batcher, int x, int y) { if (_texture != null) { X = x - Width / 2; Y = y - Height / 2; //batcher.GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer | ClearOptions.Stencil, new Vector4(0, 0, 0, 1), 0, 0); batcher.Begin(); batcher.SetStencil(_stencil.Value); //batcher.SetBlendState(_checkerBlend.Value); BlendState.AlphaBlend.ColorWriteChannels = ColorWriteChannels.Alpha; batcher.Draw2D(_texture, X, Y, Vector3.Zero); BlendState.AlphaBlend.ColorWriteChannels = ColorWriteChannels.All; //batcher.SetBlendState(null); batcher.SetStencil(null); batcher.End(); } }
public override void Render() { var start = EnableBatcher; if (start) { Batcher2D.Begin(); } RenderGame(); inUi = true; RenderUi(); inUi = false; Engine.GraphicsDevice.SetRenderTarget(null); var set = false; if (EnableClip && Camera.Instance != null) { var pos = Camera.Instance.CameraToScreen(ClipPosition) - new Vector2(Camera.Instance.Position.X % 1, Camera.Instance.Position.Y % 1) + Camera.Instance.GetComponent <ShakeComponent>().Position; Engine.GraphicsDevice.ScissorRectangle = new Rectangle((int)(pos.X * Engine.Instance.Upscale), (int)(pos.Y * Engine.Instance.Upscale), (int)(ClipSize.X * Engine.Instance.Upscale), (int)(ClipSize.Y * Engine.Instance.Upscale)); } else { set = true; Engine.GraphicsDevice.ScissorRectangle = new Rectangle((int)Engine.Viewport.X, (int)Engine.Viewport.Y, (int)(Display.Width * Engine.Instance.Upscale), (int)(Display.Height * Engine.Instance.Upscale)); } Graphics.Batch.Begin(SpriteSortMode.Immediate, BlendState, SamplerState, DepthStencilState, ClipRasterizerState, GameEffect, one); if (Camera.Instance != null) { var shake = Camera.Instance.GetComponent <ShakeComponent>(); var scale = Engine.Instance.Upscale * Camera.Instance.TextureZoom; Graphics.Render(GameTarget, new Vector2(Engine.Viewport.X + Display.Width / 2f * Engine.Instance.Upscale + scale * shake.Position.X, Engine.Viewport.Y + Display.Height / 2f * Engine.Instance.Upscale + scale * shake.Position.Y), shake.Angle, new Vector2(Camera.Instance.Position.X % 1 + Display.Width / 2f, Camera.Instance.Position.Y % 1 + Display.Height / 2f), new Vector2(scale * GameScale)); } Graphics.Batch.End(); if (!set) { Engine.GraphicsDevice.ScissorRectangle = new Rectangle((int)Engine.Viewport.X, (int)Engine.Viewport.Y, (int)(Display.Width * Engine.Instance.Upscale), (int)(Display.Height * Engine.Instance.Upscale)); } if (UiTarget != null) { Graphics.Batch.Begin(SpriteSortMode.Immediate, BlendState, SamplerState, DepthStencilState, ClipRasterizerState, UiEffect, one); if (UiEffect != null) { UiEffect.Parameters["bottom"].SetValue(1f); Graphics.Render(UiTarget, Engine.Viewport + new Vector2(0, Engine.Instance.UiUpscale)); UiEffect.Parameters["bottom"].SetValue(0f); } Graphics.Render(UiTarget, Engine.Viewport); Graphics.Batch.End(); } Engine.Instance.State?.RenderNative(); if (start) { Batcher2D.End(); } }