-
[AS3] Swapping/Arraging Depths?
Hey there FK forums! It's late, so I'm just going to jump right to the point.
I'm an AS3 noob and I'm making a game - Game Link, click to place blocks - and I'm having issues with it (Surprisingly!).
Basically, I'm trying to get the depths of all the blocks to be at the correct levels at the correct times so that the 3d effect is maintained.
I've tried many things, but have had little success.
All the instances of the blocks are stored in an array, but since it's adding them in accordance with when they're added to the stage, it doesn't help me locate them to swap depths. Is there a way to arrange them by location on the board?
Does anyone have any suggestions about how get the depths right?
Thank you in advance.
-
Hmm... I want to say you can always add to level 0, but that may cause some weird popping issues. Maybe not, have you tried that?
So addChildAt(box, 0)...
I (Love | Hate) Flash.
----
Save a version back so others may help you!
-
getChildIndex will return the index of the parsed child.
ex:
var depth=boardMC.getChildIndex(block2);
You have power within you to do whatever you wants to do.
-
You want your grid to be sorted by distance (in grid-tiles) from the centermost square (the one that's dead center - 4th row, 4th col):
PHP Code:
6 5 4 3 4 5 6 5 4 3 2 3 4 5 4 3 2 1 2 3 4 3 2 1 0 1 2 3 4 3 2 1 2 3 4 5 4 3 2 3 4 5 6 5 4 3 4 5 6
So if your blocks are all in an array already, you can just run that through a custom sort comparison to get them in the order you want:
PHP Code:
// copy the array var temp:Array = blocksArray.concat();
// sort in descending order of distance from center temp.sort(customSort);
// reset the depths for(var i:int = 0; i < temp.length; ++i){ addChild(temp[i]); }
function customSort(a:block, b:block):Number{ // calculate how far a is from middle column var xdist:int = Math.abs(4 - a.row); var ydist:int = Math.abs(4 - a.column); var aDistanceFromCenter:int = xdist + ydist;
// repeat for b var xdist:int = Math.abs(4 - b.row); var ydist:int = Math.abs(4 - b.column); var bDistanceFromCenter:int = xdist + ydist;
if(aDistanceFromCenter == bDistanceFromCenter) return 0; return((aDistanceFromCenter < bDistanceFromCenter) ? 1 : -1); }
Please use [php] or [code] tags, and mark your threads resolved 8)
-
Since the 3D part of the block is the part behind it, and that is all the same colour, with no distinguishing marks, couldn't you just separate the front from the back, and make the back follow the front or something? That way the front parts of the blocks will never have the back parts of other blocks over them...
(Doesn't answer your question, but it might work easier...)
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
|