• Advertisement
Sign in to follow this  

Flash sprite sorting problem

This topic is 4187 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Sign in to follow this  

  • Advertisement