Original Post
After ahile I almost have my sprite sorting. Here's what I have so far... First I sort all the sprites at initialization then when something moves I call this... 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?
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;
}
}
}
}
}
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;
}
}
}