I’m currently working on side scroller that has an isometric-type perspective (think Double Dragon) and the only thing I could think of to use to easily manage the depths of the MCs was a bubbleSorting algorithm. (It seemed to lend itself well to the swapChildren command).
function bubbleSortDepth():void
{
var n:int = numChildren;
var swapped:Boolean = false;
do
{
n = n-1;
swapped = false;
for(i = 0; i<=n-1; i++)
{
if(getChildAt(i).y>getChildAt(i+1).y)
{
swapChildren(getChildAt(i), getChildAt(i+1));
swapped = true;
}
}
}while(swapped);
}
Now this works fine (because I don’t have a huge amount of MCs to sort), so I guess this is more of an academic question in this case but perhaps I will wind up doing another game like this that has more MCs later on. As far as I know, bubblesorting is pretty much one of the worst sorting algorithms out there and requires on average N^2 operations to sort N items. This would really suck as the number of MCs increases since it must happen on ENTER_FRAME. Has anyone successfully adapted a better algorithm for this purpose? Not trying to get you to post your exact code as much as just an idea for me to play around with because I’m a geek like that.
Thanks!