How do I z-order of same object type [new problem]

Get help using Construct 2

Post » Tue Mar 10, 2015 3:02 pm

Hi,

i ran into a problem im not sure how to solve. For my isometric tower defense game i have managed the z-order of people and buildings with these events:
Image

for placing new towers i need something similar but
Image
doesnt work at all, i guess because it cant figure out which tower is which?
is there a way that the logic differs between two instances of the same object?
or do i have to make a workaround that relies on other values? (like both x and y position/tile that the towers stand on)
Last edited by fldr on Tue Mar 10, 2015 10:04 pm, edited 1 time in total.
B
36
S
11
G
5
Posts: 484
Reputation: 5,288

Post » Tue Mar 10, 2015 3:14 pm

I'm also curious about how you manage picking in this situation....

Since the towers don't move, you can set their Z order once at their creation or at the start of the level. Because you don't do it too often, you can afford to use an ordered ForEach to loop over them all by z order and send them to the top, one by one. This is, of course, the most horrible sorting algorithm ever, but I figure it's better than no solution at all.
B
14
S
5
G
1
Posts: 189
Reputation: 1,536

Post » Tue Mar 10, 2015 3:36 pm

You really shouldn't have any issues sorting them all a few times a second only if you're moving. Just "for each object" (ordered) by y ascending, send to front whenever you're moving, but limit it to like 30 or so milliseconds so it only runs a few times a second. There seems to be some strange opinion on these forums that this is something crazy cpu-intensive and mostly be people who've never done it. It works fine, it's how tons of things are sorted in my game. Just put everything sortable into a family (they have to be the same object type) and then just run the operation on that family whenever necessary. If your character moves slower, you can probably decrease how often it happens. You don't need to run it every tick.
B
96
S
34
G
14
Posts: 938
Reputation: 14,896

Post » Tue Mar 10, 2015 6:54 pm

bladedpenguin wrote:I'm also curious about how you manage picking in this situation....

Since the towers don't move, you can set their Z order once at their creation or at the start of the level. Because you don't do it too often, you can afford to use an ordered ForEach to loop over them all by z order and send them to the top, one by one. This is, of course, the most horrible sorting algorithm ever, but I figure it's better than no solution at all.

Thank you both!
it works really fine that way :)
and youre wright, since its only necessary when a new tower is placed it shouldnt make any performance impact.
B
36
S
11
G
5
Posts: 484
Reputation: 5,288

Post » Tue Mar 10, 2015 7:43 pm

now i got another problem i thought ive already solved :/

sometimes my code from above for setting the peoples z-order doesnt work
i figured is has something to do in which order the towers are sorted when a walker overlaps more then one tower

i made another demo, the towers are drag&drop so you can play around with different situations
if you change the place of the problematic tower it will make correct z order
i guess it has to do with the objects uid?
tryed to make something with for each(ordered) but it doesnt really work

http://fldr.de/tower7
B
36
S
11
G
5
Posts: 484
Reputation: 5,288

Post » Tue Mar 10, 2015 11:04 pm

im now trying for quite some hours everything i thought might work, but nothing.
Several different event combinations with "for each sprite","for each tower", "for each (sorted) tower by y" descending, ascending, call a function to sort everything...
because i thought it has something to do with the UID i even implemented that every tower gets rebuild sorted by its y value, descending, ascending when a key is pressed, doesnt work.
descending, ascending does change the buggy behaviour, that means its not the same towers that are affected but i didnt find a solution where every tower behaved the way i wanted.
the strange thing about it is that only some towers are affected and i cant find the missing link.
the code works perfect when the walkersprite is only overlapping one tower but with two or more it SOMETIMES doesnt work..
i did build a tower on every field thats near the street, turns out you can fix the situation by rearanging the towers, but i dont see the pattern here, all i know its not solved by rebuilding all towers by ascending or descending y values.
my head hurts
B
36
S
11
G
5
Posts: 484
Reputation: 5,288

Post » Tue Mar 10, 2015 11:27 pm

ok, heres a solution i found on the forum that works, it just works, im happy :D
Image
towers and people are both in this family
now i can delete over 50 events ^^
have to figure out how i can make this more performant (already tryed sprite"on collision"with tower instead of "every..", wasnt good) but for the moment, im just happy :)
Thanks for everybody who helped me !
B
36
S
11
G
5
Posts: 484
Reputation: 5,288

Post » Wed Mar 11, 2015 12:13 am

At some point somebody should make a plugin that implements bubble sort, if RexRainbow's plugin doesn't already....
B
14
S
5
G
1
Posts: 189
Reputation: 1,536

Post » Wed Mar 11, 2015 12:33 pm

Image

Here's my solution which works pretty fine. I think it performs quite well, but probably can be optimized a bit.
Objects can be replaced with families i guess.

I'm not sure if i got it right exactly the way i wanted, but what I was aiming for is to call the sorting function only when something moves to a new layer (Above or Behind), which it does depending on the Y position.

And here's a link to the capx file.
https://dl.dropboxusercontent.com/u/20560446/z_order_isometric.capx
Follow my progress on Twitter
or in this thread Archer Devlog
B
25
S
9
G
12
Posts: 615
Reputation: 8,150


Return to How do I....?

Who is online

Users browsing this forum: Braus and 4 guests