A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [AS3] Swapping/Arraging Depths?

  1. #1
    Junior Member
    Join Date
    May 2007

    Question [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.

  2. #2
    Senior Member
    Join Date
    Jul 2006
    San Jose, CA
    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!

  3. #3
    Junior Member
    Join Date
    Dec 2009
    getChildIndex will return the index of the parsed child.

    var depth=boardMC.getChildIndex(block2);
    You have power within you to do whatever you wants to do.

  4. #4
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Oregon, USA
    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

    //  reset the depths
    for(var i:int 0temp.length; ++i){

    //  calculate how far a is from middle column
    var xdist:int Math.abs(a.row);
    ydist:int Math.abs(a.column);
    aDistanceFromCenter:int xdist ydist;

    //  repeat for b
    var xdist:int Math.abs(b.row);
    ydist:int Math.abs(b.column);
    bDistanceFromCenter:int xdist ydist;

    aDistanceFromCenter == bDistanceFromCenter) return 0;
    aDistanceFromCenter bDistanceFromCenter) ? : -1);

    Please use [php] or [code] tags, and mark your threads resolved 8)

  5. #5
    Join Date
    Dec 2009
    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

Click Here to Expand Forum to Full Width

HTML5 Development Center