How do I Z Order Properly

Get help using Construct 2

Post » Sun Nov 23, 2014 1:35 am

cODE.png


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?
You do not have the required permissions to view the files attached to this post.
B
45
S
13
G
1
Posts: 236
Reputation: 4,010

Post » Sun Nov 23, 2014 2:27 am

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! :)
B
84
S
20
G
6
Posts: 175
Reputation: 8,156

Post » Sun Nov 23, 2014 3:36 am

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.
B
35
S
9
G
4
Posts: 201
Reputation: 5,170

Post » Sun Nov 23, 2014 4:08 am

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.
B
45
S
13
G
1
Posts: 236
Reputation: 4,010

Post » Wed Nov 26, 2014 5:04 am

corlenbelspar wrote: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.)
B
84
S
20
G
6
Posts: 175
Reputation: 8,156

Post » Wed Nov 26, 2014 7:44 am

Just remember: Computer logic and human logic work in two entirely different ways. :)
B
45
S
13
G
1
Posts: 236
Reputation: 4,010

Post » Wed Nov 26, 2014 8:07 am

NIce solution @corlenbelspar - I'll bookmark this.
Image
B
9
S
3
G
1
Posts: 346
Reputation: 1,560


Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider], brunopalermo, Nicolas951 and 14 guests