How do I Z Order Properly

0 favourites
  • 7 posts
  • [attachment=0:q987q42q][/attachment:q987q42q]

    I know this code allows you to Z order things, but when they're on the same Y coordinate they start flipping back and forth between being placed above each other and it looks weird for things like trees so how do I make it so the code causes them to also sort by X coordinate?

  • I had the same problem with a project, but I haven't worked it out yet since I'm not working on that game at this moment.

    But now that I think of it a bit; perhaps move the most important (or last, or whatever) a bit so the Y is not the same? Depends on the game your making and if that would just not be the right fit..

    Maybe not change the Y position but make one of the two the prominent one with a boolean variable, possibly give them each a random time to switch?

    I dunno.. Those are my two cents. I would like to know the answer to this as well!

  • I like to add an instance variable to my z-sort family and sort by the family's Y value + the variable. Then if two instances are overlapping I'll just pick the top instance and set it's variable to something small, like 0.1, so it can be at the same physical spot and still sort in the order I want. I also use that variable to make things that are off the ground sort correctly without having to move their centerpoint or whatever. It's just really handy for an additional layer of control.

  • What I ended up doing was made it sort in ascending order Z_sort_always.Y + (Z_sort_always.UID / (10^ceil(log10(Z_sort_always.UID)))) since the UID is going to always be unique and rather than a random variable possibly ending up the same and the two sprites still flickering. And the formula after the Y position makes the UID get added as a totally floating point value lower than 1 so nothing gets screwed up by adding something higher or equal to 1.

  • What I ended up doing was made it sort in ascending order Z_sort_always.Y + (Z_sort_always.UID / (10^ceil(log10(Z_sort_always.UID)))) since the UID is going to always be unique and rather than a random variable possibly ending up the same and the two sprites still flickering. And the formula after the Y position makes the UID get added as a totally floating point value lower than 1 so nothing gets screwed up by adding something higher or equal to 1.

    Oooh nice. I will definitely try that out! I'd sooner go for the way ahr Ech described, because I subconsciously avoid more "advanced" "mathematical" (to me seemingly complicated) solutions like yours. They're no logic for my brain, though I do understand what you've done. Thanks for sharing! (both of you.)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Just remember: Computer logic and human logic work in two entirely different ways.

  • NIce solution corlenbelspar - I'll bookmark this.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)