-
[RESOLVED] sorting movieclips according to y values
In the project I'm working on, there are towers the user can place. However, it you place a tower higher then another one, it appears infront of that one, which looks weird.
I want to be able to arrange all the towers so that that does not happen.
There is an sprite called towerHolder holding, which all the towers are children of, and an array called towerArray, which the towers get pushed to when they are created.
I tried clearing towerHolder, then running the sortOn() function on the array, and then adding each tower back to the towerHolder, but the towers just seem to be randomly placing themselves irrelevent to their height.
Here's my code for the relevant parts:
Actionscript Code:
function clearTowers():void { while (towerHolder.numChildren > 0) { towerHolder.removeChildAt(0); } }
function orderTowers():void { clearTowers(); towerArray = towerArray.sortOn(y, Array.NUMERIC); for each (var tower in towerArray) { towerHolder.addChild(tower); } }
So yeah if you could help me so that I have a function I can called to order the towers correctly, that would be great.
Last edited by Jezzamon; 11-06-2010 at 11:45 PM.
Reason: tyops
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|