From 08a31231e9811d7ddee415501077dcf2972084c6 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Wed, 19 Feb 2020 17:33:09 -0500 Subject: [PATCH] Draw LinesOfSight behind most other things. Also remove the currently-unneeded lightingTarget. GitOrigin-RevId: 95d96d966a07624b2c6c648d7c208cfa16acd2b9 --- Shared/Scene.cs | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/Shared/Scene.cs b/Shared/Scene.cs index 4b356f0..f67b431 100644 --- a/Shared/Scene.cs +++ b/Shared/Scene.cs @@ -12,8 +12,7 @@ namespace SemiColinGames { readonly Camera camera; readonly RenderTarget2D sceneTarget; - readonly RenderTarget2D lightingTarget; - readonly BasicEffect lightingEffect; + readonly BasicEffect basicEffect; readonly SpriteBatch spriteBatch; public Scene(GraphicsDevice graphics, Camera camera) { @@ -23,11 +22,8 @@ namespace SemiColinGames { sceneTarget = new RenderTarget2D( graphics, camera.Width, camera.Height, false /* mipmap */, graphics.PresentationParameters.BackBufferFormat, DepthFormat.Depth24); - lightingTarget = new RenderTarget2D( - graphics, camera.Width, camera.Height, false /* mipmap */, - graphics.PresentationParameters.BackBufferFormat, DepthFormat.Depth24); - lightingEffect = new BasicEffect(graphics) { + basicEffect = new BasicEffect(graphics) { World = Matrix.CreateTranslation(0, 0, 0), View = Matrix.CreateLookAt(Vector3.Backward, Vector3.Zero, Vector3.Up), VertexColorEnabled = true @@ -42,8 +38,7 @@ namespace SemiColinGames { public void Dispose() { sceneTarget.Dispose(); - lightingTarget.Dispose(); - lightingEffect.Dispose(); + basicEffect.Dispose(); spriteBatch.Dispose(); GC.SuppressFinalize(this); } @@ -59,7 +54,7 @@ namespace SemiColinGames { graphics.SetRenderTarget(sceneTarget); graphics.Clear(backgroundColor); - // Draw background. + // Draw parallax backgrounds. spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearWrap, null, null); Rectangle bgTarget = new Rectangle(0, 0, camera.Width, camera.Height); @@ -73,30 +68,29 @@ namespace SemiColinGames { } spriteBatch.End(); + // Draw lines of sight. + basicEffect.Projection = camera.Projection; + if (Debug.Enabled) { + linesOfSight.Draw(graphics, basicEffect); + } + // Set up transformation matrix for drawing world objects. Matrix transform = Matrix.CreateTranslation(-camera.Left, -camera.Top, 0); - spriteBatch.Begin( - SpriteSortMode.Deferred, null, SamplerState.LinearWrap, null, null, null, transform); // Draw player. + spriteBatch.Begin( + SpriteSortMode.Deferred, null, SamplerState.LinearWrap, null, null, null, transform); player.Draw(spriteBatch); + spriteBatch.End(); // Draw foreground tiles. + spriteBatch.Begin( + SpriteSortMode.Deferred, null, SamplerState.LinearWrap, null, null, null, transform); world.Draw(spriteBatch); - - // Aaaaand we're done. spriteBatch.End(); - // Draw lighting to lightingTarget. - graphics.SetRenderTarget(lightingTarget); - graphics.Clear(new Color(0, 0, 0, 0f)); - lightingEffect.Projection = camera.Projection; - if (Debug.Enabled) { - linesOfSight.Draw(graphics, lightingEffect); - } - // Draw debug rects & lines on top. - Debug.Draw(graphics, lightingEffect); + Debug.Draw(graphics, basicEffect); // Draw sceneTarget to screen. graphics.SetRenderTarget(null); @@ -106,7 +100,6 @@ namespace SemiColinGames { Rectangle drawRect = new Rectangle( 0, 0, graphics.Viewport.Width, graphics.Viewport.Height); spriteBatch.Draw(sceneTarget, drawRect, Color.White); - spriteBatch.Draw(lightingTarget, drawRect, Color.White); // Draw debug toasts. Debug.DrawToasts(spriteBatch);