A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: multi-character z sorting / swapdepths on Y position

  1. #1
    Member
    Join Date
    Jun 2000
    Posts
    47

    multi-character z sorting / swapdepths on Y position

    hi could someone point me to explanation on how to implement z sorting on multiple characters based on their Y position.

    presumably if 2 characters are at the same Y position, then the one shown in front of the other could be the last that moved.

    here is what i would be applying it to:
    http://www.interference.co.uk/test/southpark/index.htm

    i've done a search of swapdepths on the board and there's about 500 articles so i'm not sure where to start.

    thanks
    j

  2. #2
    Ihoss
    Guest
    if you have duplicated the movieclip, then you also set the depth of the movieclip. the higher the depth, the further in front it is. you can also use the swapDepth(); doce to change the depth of a movieclip. if you want to make something seem three dimenrional and you have made a floor in your movie which goes backwards into the horizon (not only a line) then you can make characters seem further behind some others by getting their _y position and using it to set their depth. you can also use the _y position to set the characters size. i hope i answered your question.

  3. #3
    Junior Member
    Join Date
    Mar 2003
    Posts
    24

    Re: multi-character z sorting / swapdepths on Y position

    Originally posted by jmp909
    here is what i would be applying it to:
    http://www.interference.co.uk/test/southpark/index.htm
    ahahahahahah
    however can't you remove that white outline around the char?
    ...just to be perfectionist :P

  4. #4
    w00t io::pred's Avatar
    Join Date
    Mar 2003
    Location
    Sydney, Australia
    Posts
    163
    Z sorting as per _y coordinate..

    Say you have a screen size of 400 x 600..

    to get ones depth depending on an x,y coordinate:

    width = 400;
    height = 600;
    this.swapDepth(this._y*width+this._x);

  5. #5
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    wouldn't your calculation produce a number > 16000 odd which is the maximum number for flash when using swapdepth?
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  6. #6
    w00t io::pred's Avatar
    Join Date
    Mar 2003
    Location
    Sydney, Australia
    Posts
    163
    Swapdepths works higher than that that, its somewhere closer to 1.6 million..

  7. #7
    with characters like that the _y is all that matters for swap depth.. I give each character an ID

    So
    character1.id=1
    character2.id=2
    character3.id=3

    charater1.swapDepth(_y*1000+character1.id)
    charater2.swapDepth(_y*1000+character2.id)
    charater3.swapDepth(_y*1000+character3.id)

    The id make sure 2 characters will never have the same depth. but it also means if character 1 and 3 have the same _y then character 3 will always be on top.

    Nugget

  8. #8
    w00t io::pred's Avatar
    Join Date
    Mar 2003
    Location
    Sydney, Australia
    Posts
    163
    That also works, but it means that each object requires more overhead, well actually, it is basically the same way I said, however there is no _x sorting

  9. #9
    Member
    Join Date
    Jun 2000
    Posts
    47
    >> white outline

    its a bitmap i pasted in, eventually it would be vectors

    >>to get ones depth depending on an x,y coordinate:

    i believe the x coordinate is irrelevant in this case

    >> charater1.swapDepth(_y*1000+character1.id)

    is it possible i can avoid running swapDepths on *all* characters when a character moves. is it safe to only do it on a character who changes position?

    thanks all
    j.

  10. #10
    w00t io::pred's Avatar
    Join Date
    Mar 2003
    Location
    Sydney, Australia
    Posts
    163
    yes. the use of nuggets method and mine is much of a sameness, they do the exact same thing, however his keeps track of a depth variable.

  11. #11
    Pred the 1 bug with yours is if 2 people have the same x and y. they theyll have the same depth wich flash won't let you do (maybe different in mx, not sure). I know like in flash 5 one of the objects would basically disapear..

  12. #12
    and yes you only need to run swapDepth on the character being moved.

  13. #13
    w00t io::pred's Avatar
    Join Date
    Mar 2003
    Location
    Sydney, Australia
    Posts
    163
    And the one bug with your is if there is more than 1000 objects >=)

    Omg.. its 6am in the morning.. im about to die.

  14. #14
    heh, correct =)

  15. #15
    Illuminatus! fospher.com's Avatar
    Join Date
    Jan 2002
    Location
    5th Dimension
    Posts
    2,185
    well you could set a depth for all the characters, then just swap numbers.

    swapDepths(5) if another south park character is '4'.
    i like the game btw

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