After ahile I almost have my sprite sorting. Here's what I have so far...
First I sort all the sprites at initialization
function InitEntitySort():Void
{
var Temp:Number = 0;
for (var e:Number = 0; e < LiveEntitiesCreated; e++)
{
Temp = CreatedLiveEntity[e].Value.EntityDepth;
for (var oe = 0; oe < LiveEntitiesCreated; oe++)
{
if(CreatedLiveEntity[e].Value.EntityNum < CreatedLiveEntity[oe].Value.EntityNum)
{
if (CreatedLiveEntity[e].Value.EntityBGPosY > CreatedLiveEntity[oe].Value.EntityBGPosY)
{
CreatedLiveEntity[e].Value.EntityDepth = CreatedLiveEntity[oe].Value.EntityDepth;
CreatedLiveEntity[oe].Value.EntityDepth = Temp;
}
}
}
}
}
then when something moves I call this...
function CheckEntityDepths (EntityToCheck:Object):Void
{
EntityToCheck.Value.EntityDepthSwapped = false;
for (var oe = 0; oe < LiveEntitiesCreated; oe++)
{
if ((EntityToCheck.Value.EntityInstance._y == CreatedLiveEntity[oe].Value.EntityInstance._y) && (EntityToCheck.Value.EntityDepthSwapped == false))
{
EntityToCheck.Value.EntityInstance.swapDepths(CreatedLiveEntity[oe].Value.EntityInstance);
EntityToCheck.Value.DepthChecked = true;
}
}
}
The sorting works fine until something stops at the same Y position as something else then goes the opposite direction which results in the sprite being incorrectly swapped, it's postion is behind another sprite but his graphic is in front of them. Anyone have an idea as to how I can solve this?
Artist 1st - Programmer 2nd(I'll get some material linked here sometime to support these claims, haha)