From d035d3bfb2ee8ebafa7d6726687632e5496b44db Mon Sep 17 00:00:00 2001 From: Regalis Date: Mon, 28 Nov 2016 17:50:38 +0200 Subject: [PATCH] Structure depth sorting based on ID (overlapping structures don't "flicker" on top of each other) --- Subsurface/Source/Map/Structure.cs | 7 +++++-- Subsurface/Source/Sprite.cs | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Subsurface/Source/Map/Structure.cs b/Subsurface/Source/Map/Structure.cs index b79716e4a..a361a8189 100644 --- a/Subsurface/Source/Map/Structure.cs +++ b/Subsurface/Source/Map/Structure.cs @@ -503,6 +503,9 @@ namespace Barotrauma Vector2 drawOffset = Submarine == null ? Vector2.Zero : Submarine.DrawPosition; + float depth = prefab.sprite.Depth; + depth -= (ID % 255) * 0.000001f; + if (back && damageEffect == null) { if (prefab.BackgroundSprite != null) @@ -550,8 +553,8 @@ namespace Barotrauma spriteBatch, new Vector2(sections[i].rect.X + drawOffset.X, -(sections[i].rect.Y + drawOffset.Y)), new Vector2(sections[i].rect.Width, sections[i].rect.Height), - Vector2.Zero, color, - textureOffset); + Vector2.Zero, color, + textureOffset, depth); } } diff --git a/Subsurface/Source/Sprite.cs b/Subsurface/Source/Sprite.cs index 2f377e951..f427ff169 100644 --- a/Subsurface/Source/Sprite.cs +++ b/Subsurface/Source/Sprite.cs @@ -223,12 +223,14 @@ namespace Barotrauma DrawTiled(spriteBatch, pos, targetSize, Vector2.Zero, color); } - public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Vector2 startOffset, Color color, Point offset) + public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Vector2 startOffset, Color color, Point offset, float? overrideDepth = null) { //how many times the texture needs to be drawn on the x-axis int xTiles = (int)Math.Ceiling((targetSize.X + startOffset.X) / sourceRect.Width); //how many times the texture needs to be drawn on the y-axis int yTiles = (int)Math.Ceiling((targetSize.Y + startOffset.Y) / sourceRect.Height); + + float depth = overrideDepth == null ? this.depth : (float)overrideDepth; Rectangle texPerspective = sourceRect;