Draw LinesOfSight behind most other things.

Also remove the currently-unneeded lightingTarget.

GitOrigin-RevId: 95d96d966a07624b2c6c648d7c208cfa16acd2b9
This commit is contained in:
Colin McMillen 2020-02-19 17:33:09 -05:00
parent 2fe8e53e77
commit 08a31231e9

View File

@ -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();
// 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.
player.Draw(spriteBatch);
// Draw foreground tiles.
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;
// Draw lines of sight.
basicEffect.Projection = camera.Projection;
if (Debug.Enabled) {
linesOfSight.Draw(graphics, lightingEffect);
linesOfSight.Draw(graphics, basicEffect);
}
// Set up transformation matrix for drawing world objects.
Matrix transform = Matrix.CreateTranslation(-camera.Left, -camera.Top, 0);
// 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);
spriteBatch.End();
// 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);