My problem is I Have an isometric grid, just based on the X,Y values: Each time you click a button for instance road than this item is pushed to an array()
//
addChild(roadTiles);
gameAssets.push(roadTiles);
arrangeAssets();
//
My arrangeAssets method just checks the array "no point posting as it fails most of the time.gennerally some items update but not all. So im hoping some one has a solution to check X,Y value then setChildIndex of Array. I have looked, keep getting reffered to 3rd party as3 engines which im not interested in as i want to make my own and have better understanding.
or is this not possible as im only using an X,Y grid
arrangeAssets();{
var i:int = gameAssets.length;
while(i--){
if (getChildIndex(sortedItems[i]) != i) {
gameAssets.sortOn("y", Array.NUMERIC);
setChildIndex(gameAssets[i], i);
}
}
I only add the items on top of the grass grid into the array.
assuming that the left most point is x: 0, y:0
the tiles are covering each other going from a high x
and low y
to a low x
and high y
values.
I would add a weight
variable (call it what you like), and calculate it from (totalx - x) * y
this would have the top-most corner have a value of 0, and the bottom most have the highest value. every row (diagonal really) would be the same.
Then sort on the weight
and you have a list of items in the relative z stack.
this doesn't really address the setchildIndex, because you can't have two items there. a hack would be to remove all and add them back in the order. (you could have a temp child, that you add as children to, that way you don't have to remove the children as it is done automatically)
I found this image that shows the weight
as _y
from http://www.kirupa.com/developer/isometric/depth_sorting.htm
the _y is the same because (totalx - x) * y
values horizontally are the same
totalx
is the number of rows(or columns) along the x axis, I had x - totalx
instead of totalx - x
I edited the answe - Daniel 2012-04-05 17:06
arrangeAssets
code, and give an example of a new roatTiles instance you want to push into gameAssets and how it should be handled - sberry 2012-04-05 16:10