From e2c7b684de179f2aa05d7560e22f937153775231 Mon Sep 17 00:00:00 2001
From: Joonas Rikkonen
Date: Thu, 11 Jan 2018 13:32:21 +0200
Subject: [PATCH] Fixed character limb rendering order not being consistent
(limbs with the same depth value being randomly drawn behind or in front of
each other)
---
.../Content/Items/Jobgear/captaingear.xml | 18 +++++++++---------
.../Source/Characters/Animation/Ragdoll.cs | 11 +++++++----
2 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/Barotrauma/BarotraumaShared/Content/Items/Jobgear/captaingear.xml b/Barotrauma/BarotraumaShared/Content/Items/Jobgear/captaingear.xml
index 198ad5745..44532a7e7 100644
--- a/Barotrauma/BarotraumaShared/Content/Items/Jobgear/captaingear.xml
+++ b/Barotrauma/BarotraumaShared/Content/Items/Jobgear/captaingear.xml
@@ -26,13 +26,13 @@
-
+
-
-
+
+
-
-
+
+
@@ -48,11 +48,11 @@
-
-
+
+
-
-
+
+
diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Animation/Ragdoll.cs b/Barotrauma/BarotraumaShared/Source/Characters/Animation/Ragdoll.cs
index 46625bc4d..a4a8fb54e 100644
--- a/Barotrauma/BarotraumaShared/Source/Characters/Animation/Ragdoll.cs
+++ b/Barotrauma/BarotraumaShared/Source/Characters/Animation/Ragdoll.cs
@@ -356,19 +356,22 @@ namespace Barotrauma
(joint.LowerLimit + joint.UpperLimit) / 2.0f);
}
+ //make sure every character gets drawn at a distinct "layer"
+ //(instead of having some of the limbs appear behind and some in front of other characters)
float startDepth = 0.1f;
float increment = 0.001f;
-
foreach (Character otherCharacter in Character.CharacterList)
{
- if (otherCharacter==character) continue;
- startDepth+=increment;
+ if (otherCharacter == character) continue;
+ startDepth += increment;
}
+ //make sure each limb has a distinct depth value
+ List depthSortedLimbs = Limbs.OrderBy(l => l.sprite == null ? 0.0f : l.sprite.Depth).ToList();
foreach (Limb limb in Limbs)
{
if (limb.sprite != null)
- limb.sprite.Depth = startDepth + limb.sprite.Depth * 0.0001f;
+ limb.sprite.Depth = startDepth + depthSortedLimbs.IndexOf(limb) * 0.00001f;
}
Limb torso = GetLimb(LimbType.Torso);