Draw LinesOfSight behind most other things.
Also remove the currently-unneeded lightingTarget. GitOrigin-RevId: 95d96d966a07624b2c6c648d7c208cfa16acd2b9
This commit is contained in:
parent
2fe8e53e77
commit
08a31231e9
@ -12,8 +12,7 @@ namespace SemiColinGames {
|
|||||||
readonly Camera camera;
|
readonly Camera camera;
|
||||||
|
|
||||||
readonly RenderTarget2D sceneTarget;
|
readonly RenderTarget2D sceneTarget;
|
||||||
readonly RenderTarget2D lightingTarget;
|
readonly BasicEffect basicEffect;
|
||||||
readonly BasicEffect lightingEffect;
|
|
||||||
readonly SpriteBatch spriteBatch;
|
readonly SpriteBatch spriteBatch;
|
||||||
|
|
||||||
public Scene(GraphicsDevice graphics, Camera camera) {
|
public Scene(GraphicsDevice graphics, Camera camera) {
|
||||||
@ -23,11 +22,8 @@ namespace SemiColinGames {
|
|||||||
sceneTarget = new RenderTarget2D(
|
sceneTarget = new RenderTarget2D(
|
||||||
graphics, camera.Width, camera.Height, false /* mipmap */,
|
graphics, camera.Width, camera.Height, false /* mipmap */,
|
||||||
graphics.PresentationParameters.BackBufferFormat, DepthFormat.Depth24);
|
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),
|
World = Matrix.CreateTranslation(0, 0, 0),
|
||||||
View = Matrix.CreateLookAt(Vector3.Backward, Vector3.Zero, Vector3.Up),
|
View = Matrix.CreateLookAt(Vector3.Backward, Vector3.Zero, Vector3.Up),
|
||||||
VertexColorEnabled = true
|
VertexColorEnabled = true
|
||||||
@ -42,8 +38,7 @@ namespace SemiColinGames {
|
|||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
sceneTarget.Dispose();
|
sceneTarget.Dispose();
|
||||||
lightingTarget.Dispose();
|
basicEffect.Dispose();
|
||||||
lightingEffect.Dispose();
|
|
||||||
spriteBatch.Dispose();
|
spriteBatch.Dispose();
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
@ -59,7 +54,7 @@ namespace SemiColinGames {
|
|||||||
graphics.SetRenderTarget(sceneTarget);
|
graphics.SetRenderTarget(sceneTarget);
|
||||||
graphics.Clear(backgroundColor);
|
graphics.Clear(backgroundColor);
|
||||||
|
|
||||||
// Draw background.
|
// Draw parallax backgrounds.
|
||||||
spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearWrap, null, null);
|
spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearWrap, null, null);
|
||||||
Rectangle bgTarget = new Rectangle(0, 0, camera.Width, camera.Height);
|
Rectangle bgTarget = new Rectangle(0, 0, camera.Width, camera.Height);
|
||||||
|
|
||||||
@ -73,30 +68,29 @@ namespace SemiColinGames {
|
|||||||
}
|
}
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
// Set up transformation matrix for drawing world objects.
|
// Draw lines of sight.
|
||||||
Matrix transform = Matrix.CreateTranslation(-camera.Left, -camera.Top, 0);
|
basicEffect.Projection = camera.Projection;
|
||||||
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;
|
|
||||||
if (Debug.Enabled) {
|
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.
|
// Draw debug rects & lines on top.
|
||||||
Debug.Draw(graphics, lightingEffect);
|
Debug.Draw(graphics, basicEffect);
|
||||||
|
|
||||||
// Draw sceneTarget to screen.
|
// Draw sceneTarget to screen.
|
||||||
graphics.SetRenderTarget(null);
|
graphics.SetRenderTarget(null);
|
||||||
@ -106,7 +100,6 @@ namespace SemiColinGames {
|
|||||||
Rectangle drawRect = new Rectangle(
|
Rectangle drawRect = new Rectangle(
|
||||||
0, 0, graphics.Viewport.Width, graphics.Viewport.Height);
|
0, 0, graphics.Viewport.Width, graphics.Viewport.Height);
|
||||||
spriteBatch.Draw(sceneTarget, drawRect, Color.White);
|
spriteBatch.Draw(sceneTarget, drawRect, Color.White);
|
||||||
spriteBatch.Draw(lightingTarget, drawRect, Color.White);
|
|
||||||
|
|
||||||
// Draw debug toasts.
|
// Draw debug toasts.
|
||||||
Debug.DrawToasts(spriteBatch);
|
Debug.DrawToasts(spriteBatch);
|
||||||
|
Loading…
Reference in New Issue
Block a user