Sorts objects by Transformation
This commit is contained in:
parent
7afec9c9ef
commit
b45a10b676
1 changed files with 25 additions and 0 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue