Structure depth sorting based on ID (overlapping structures don't "flicker" on top of each other)

This commit is contained in:
Regalis
2016-11-28 17:50:38 +02:00
parent 5779de0e17
commit d035d3bfb2
2 changed files with 8 additions and 3 deletions
+4 -1
View File
@@ -503,6 +503,9 @@ namespace Barotrauma
Vector2 drawOffset = Submarine == null ? Vector2.Zero : Submarine.DrawPosition; Vector2 drawOffset = Submarine == null ? Vector2.Zero : Submarine.DrawPosition;
float depth = prefab.sprite.Depth;
depth -= (ID % 255) * 0.000001f;
if (back && damageEffect == null) if (back && damageEffect == null)
{ {
if (prefab.BackgroundSprite != null) if (prefab.BackgroundSprite != null)
@@ -551,7 +554,7 @@ namespace Barotrauma
new Vector2(sections[i].rect.X + drawOffset.X, -(sections[i].rect.Y + drawOffset.Y)), new Vector2(sections[i].rect.X + drawOffset.X, -(sections[i].rect.Y + drawOffset.Y)),
new Vector2(sections[i].rect.Width, sections[i].rect.Height), new Vector2(sections[i].rect.Width, sections[i].rect.Height),
Vector2.Zero, color, Vector2.Zero, color,
textureOffset); textureOffset, depth);
} }
} }
+3 -1
View File
@@ -223,13 +223,15 @@ namespace Barotrauma
DrawTiled(spriteBatch, pos, targetSize, Vector2.Zero, color); 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 //how many times the texture needs to be drawn on the x-axis
int xTiles = (int)Math.Ceiling((targetSize.X + startOffset.X) / sourceRect.Width); int xTiles = (int)Math.Ceiling((targetSize.X + startOffset.X) / sourceRect.Width);
//how many times the texture needs to be drawn on the y-axis //how many times the texture needs to be drawn on the y-axis
int yTiles = (int)Math.Ceiling((targetSize.Y + startOffset.Y) / sourceRect.Height); int yTiles = (int)Math.Ceiling((targetSize.Y + startOffset.Y) / sourceRect.Height);
float depth = overrideDepth == null ? this.depth : (float)overrideDepth;
Rectangle texPerspective = sourceRect; Rectangle texPerspective = sourceRect;
texPerspective.Location += offset; texPerspective.Location += offset;