Fixed character limb rendering order not being consistent (limbs with the same depth value being randomly drawn behind or in front of each other)

This commit is contained in:
Joonas Rikkonen
2018-01-11 13:32:21 +02:00
parent aa0fdfb790
commit e2c7b684de
2 changed files with 16 additions and 13 deletions

View File

@@ -26,13 +26,13 @@
<Body width="52" height="17" density="30"/>
<Wearable slots="Any,Torso">
<sprite texture="captainTorso.png" limb="Torso" sourcerect="0,3,30,58" origin="0.5,0.48" depth="0.01"/>
<sprite texture="captainTorso.png" limb="Torso" sourcerect="0,3,30,58" origin="0.5,0.48" depthlimb="Head"/>
<sprite texture="captainTorso.png" limb="RightHand" sourcerect="47,0,15,39" origin="0.45,0.6"/>
<sprite texture="captainTorso.png" limb="LeftHand" sourcerect="47,0,15,39" origin="0.45,0.6" depth="0.14"/>
<sprite texture="captainTorso.png" limb="RightHand" sourcerect="47,0,15,39" origin="0.45,0.65"/>
<sprite texture="captainTorso.png" limb="LeftHand" sourcerect="47,0,15,39" origin="0.45,0.65"/>
<sprite texture="captainTorso.png" limb="RightArm" sourcerect="30,0,17,42" origin="0.5,0.5" depth="0.005" hidelimb="true"/>
<sprite texture="captainTorso.png" limb="LeftArm" sourcerect="30,0,17,42" origin="0.5,0.5" depth="0.13" hidelimb="true"/>
<sprite texture="captainTorso.png" limb="RightArm" sourcerect="30,0,17,42" origin="0.5,0.5" hidelimb="true"/>
<sprite texture="captainTorso.png" limb="LeftArm" sourcerect="30,0,17,42" origin="0.5,0.5" hidelimb="true"/>
</Wearable>
</Item>
@@ -48,11 +48,11 @@
<Wearable slots="Any,Legs">
<sprite texture="captainLegs.png" limb="Waist" sourcerect="0,0,1,1" origin="0.5,0.5" hidelimb="true"/>
<sprite texture="captainLegs.png" limb="RightThigh" sourcerect="52,34,28,46" origin="0.5,0.5" depth="0.10" hidelimb="true"/>
<sprite texture="captainLegs.png" limb="LeftThigh" sourcerect="52,34,28,46" origin="0.5,0.5" depth="0.14" hidelimb="true"/>
<sprite texture="captainLegs.png" limb="RightThigh" sourcerect="52,34,28,46" origin="0.5,0.5" hidelimb="true"/>
<sprite texture="captainLegs.png" limb="LeftThigh" sourcerect="52,34,28,46" origin="0.5,0.5" hidelimb="true"/>
<sprite texture="captainLegs.png" limb="RightLeg" sourcerect="31,0,21,49" origin="0.5,0.5" depth="0.11" hidelimb="true"/>
<sprite texture="captainLegs.png" limb="LeftLeg" sourcerect="31,0,21,49" origin="0.5,0.5" depth="0.15" hidelimb="true"/>
<sprite texture="captainLegs.png" limb="RightLeg" sourcerect="31,0,21,49" origin="0.5,0.5" hidelimb="true"/>
<sprite texture="captainLegs.png" limb="LeftLeg" sourcerect="31,0,21,49" origin="0.5,0.5" hidelimb="true"/>
</Wearable>
</Item>
</Items>

View File

@@ -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<Limb> 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);