So, I have an array with a width of 5, a height of 5, and a depth of 2.
And, I have a sprite with a width of 70 and a height of 100.
For testing purposes, the sprite that I am using is intended to be a cube viewed from an orthogonal perspective.
Next what I do, is best demonstrated if I first start with another image.
On a triggered event I spawn a sprite using the "for each element" condition of the array.
The sprite has 3 instance variables, "arrayX", "arrayY", and "arrayZ". I don't know what order the "for each element" conditions uses to loop through the array, but that isn't particularly important. The intention is to essentially have a sprite (only one sprite) linked to each position in the array.
Each time an object is created, I set it's instance variable e.g. "arrayX" to the current position in each dimension using Array.CurX/Y/Z.
Once this is done I then use these instance variables to offset the position of the sprite in order to create a grid layout. Importantly though, there is a third dimension, so I offset the Y more depending on the sprite's "arrayZ" value, in this case either 0 or 1 I believe.
On layout start, I get this
Which, so far, is good and is exactly what I expected.
Next, I have a function that I thought would be rather simple. When the function "sortz" is called, a "for each" loop is run, ordered by the sprite's "arrayZ" variable, the sprite is moved to the top of the layer. This should first run through all the sprites with an "arrayZ" value of 0, move them to the top of the layer, then move onto the sprites with an "arrayZ" value of 1 and move them to the top.
Since no sprite with the same "arrayZ" value should share the same X and Y position on the array, it should create the effect of a stack of blocks.
What I get is this
What I expected to get is this
I'm not really sure where to go from here. I had thought that if I had a sprite corresponding to each position in the array that the rest would be simple. I've been through the manual section regarding arrays and checked the forums for details on using 3D arrays.
Also, using a "for each" loop, I've counted and there are 25 sprites with an "arrayZ" value of 0 and 25 with a value of 1. So I have the correct number of sprites in each layer.
Note: I add "128" to each sprite's X and Y so that the group will be moved down and away from the top left corner of the viewport. This allows me to see all the sprites. The results are the same with or without this so I don't believe it is related to my problem.
If necessary I can clarify further and even upload an example capx, but perhaps the solutions is something simple that I am overlooking.