Sign in to follow this  
etsuja

Flash sprite sorting problem

Recommended Posts

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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this