@starry-abyss I mean
override public function add(Object:FlxBasic):FlxBasic
{
super.add(Object);
sortSpritesByZ();
return Object;
}
Which is meant to be cleaner than having to remember to call sort
every time I call add
. This is working now (I was calling sortSpritesByZ()
before super.add(Object)
and not after ), but there's still the issue of this not updating if I change a sprite's Z
. Since the property comes from an Interface, I can't really have a set
behaviour. Anyone have any ideas?
(By the way; flicker can be solved using
function sortSpritesByZ() {
sort(function(Order:Int, entityA:FlxBasic, entityB:FlxBasic):Int {
var zA:Int = 0;
var zB:Int = 0;
if (Std.is(entityA, IZSortable)) zA = cast(entityA, IZSortable).Z;
if (Std.is(entityB, IZSortable)) zB = cast(entityB, IZSortable).Z;
if (zA == zB)
zB++;
return FlxSort.byValues(Order, zA, zB);
}, FlxSort.ASCENDING);
}
)