Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void DrawStencil(SpriteBatch spriteBatch, GraphicsDeviceManager graphics, Matrix transformMatrix)
- {
- var m = Matrix.CreateOrthographicOffCenter(0,
- GameWorld.Instance.Graphics.GraphicsDevice.PresentationParameters.BackBufferWidth,
- GameWorld.Instance.Graphics.GraphicsDevice.PresentationParameters.BackBufferHeight,
- 0, 0, 1
- );
- var a = new AlphaTestEffect(GameWorld.Instance.Graphics.GraphicsDevice)
- {
- Projection = m,
- VertexColorEnabled = true,
- ReferenceAlpha = 0,
- };
- var s1 = new DepthStencilState
- {
- StencilEnable = true,
- StencilFunction = CompareFunction.Always,
- StencilPass = StencilOperation.Replace,
- ReferenceStencil = 1,
- DepthBufferEnable = false,
- };
- var s2 = new DepthStencilState
- {
- StencilEnable = true,
- StencilFunction = CompareFunction.LessEqual,
- StencilPass = StencilOperation.Keep,
- ReferenceStencil = 1,
- };
- var goPos = GameWorld.Instance.CurrentLevel.CurrentCamera.WorldToScreenPoint(Transform.WorldPosition);
- var goSize = new Vector2(.7f);
- var origin = _ownRenderer.Size*_ownRenderer.Pivot;
- GameWorld.Instance.SpriteBatch.Begin(SpriteSortMode.FrontToBack, depthStencilState: s1, effect: a);
- spriteBatch.Draw(_ownRenderer.Sprite.Texture,
- sourceRectangle: _ownRenderer.Sprite.Rect,
- position: goPos,
- rotation: Transform.WorldRotation * MathUtils.DegreeToRadian,
- origin: origin,
- scale: goSize,
- color: _ownRenderer.Color,
- effects: _ownRenderer.Effect);
- GameWorld.Instance.SpriteBatch.End();
- GameWorld.Instance.SpriteBatch.Begin(SpriteSortMode.FrontToBack, depthStencilState: s2);
- spriteBatch.Draw(GameWorld.Instance.Content.Load<Texture2D>("Sprites/Styles/Stripes"),
- sourceRectangle: _ownRenderer.Sprite.Rect,
- position: goPos,
- rotation: Transform.WorldRotation * MathUtils.DegreeToRadian,
- origin: origin,
- scale: goSize,
- color: _ownRenderer.Color,
- effects: _ownRenderer.Effect);
- GameWorld.Instance.SpriteBatch.End();
- graphics.GraphicsDevice.Clear(ClearOptions.Stencil, Color.Gray, 0, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement