Sorts objects by Transformation

This commit is contained in:
Michel Fedde 2021-03-27 18:07:52 +01:00
parent 7afec9c9ef
commit b45a10b676

View file

@ -1,7 +1,9 @@
#region usings
using System;
using SM.Base.Scene;
using SM.Base.Types;
using SM.Base.Window;
using SM2D.Types;
#endregion
@ -16,5 +18,28 @@ namespace SM2D.Scene
{
Transform.Size = new CVector2(1);
}
public override void Draw(DrawContext context)
{
this.Sort(Comparitor);
base.Draw(context);
}
private int Comparitor(IShowItem a, IShowItem b)
{
if (a is ITransformItem<Transformation> ta)
{
if (b is ITransformItem<Transformation> tb)
{
return (int)((ta.Transform.GetMatrix()[3, 2] - tb.Transform.GetMatrix()[3, 2]) * Transformation.ZIndexPercision);
}
else return 1;
}
else
{
return -1;
}
}
}
}