Compare the Z order between two instances?

Get help using Construct 2

Post » Sun Aug 30, 2015 3:12 pm

I would like to have 1 object, with lots of instances of it on the layout. I want to make it so that when the player touches one of the instances, and there is no other instances that is overlapping it and above it in the z order, only than will it be destroyed. Sort of like throwing a bunch of cards on the table, and you can only pick those that have no cards on top of it.

Since I would like to use just one object, I was thinking of comparing the z order between the 2 instances if they overlap and check if the one touched is higher in the z order. Problem is I am not sure how to get the UID for the overlapped instances.

Or is there a better way to achieve this effect?
B
46
S
23
G
31
Posts: 693
Reputation: 20,637

Post » Sun Aug 30, 2015 3:24 pm

I know that clickteam fusion has built in layer plugin, but construct 2 never got one.
there is the Rex Z layer plugin, but it doesnt have a general use "Compare all to Variable" which SUCKS.
B
4
Posts: 27
Reputation: 254

Post » Sun Aug 30, 2015 3:59 pm

@rekjl (and @jeebroniz - C2 can do exactly what rekjl wants using built in Z-order functions)

It doesn't work to compare an object to others of the same object type directly - so what you have to do is make a family and put your object in that.

then, when you click on an instance of your object, you can test to see if any FamilyObjects are overlapping. you can use PickCount to see how many there are, and you can loop through them to see if their Zindex is greater than the original object's Zindex to know if any are on top of it.

one other thing to watch out for is the initial click could click on several instances of the object if you had a bunch in one spot. So, use the "Pick Top/Bottom" (and select top) to get just the one object you want, then look for overlapping family members.
B
97
S
34
G
20
Posts: 438
Reputation: 17,790

Post » Sun Aug 30, 2015 4:10 pm

AllanR wrote:@rekjl (and @jeebroniz - C2 can do exactly what rekjl wants using built in Z-order functions)
.


What built in Z order? There is none, the For Each (Ordered) has abysmal performance. But if im wrong just tell me what it is because I cant find it and Ive tried every way possible for ordering between 10 or more dynamic objects with variables controlling depth.

Game maker also has this with depth.
B
4
Posts: 27
Reputation: 254

Post » Sun Aug 30, 2015 4:23 pm

@jeebroniz, yes there is a z-order in c2, it is at the bottom part of the events in each object's event box. I can't really say much about it cause I am actually just starting to make use of it now.

@AllanR, thanks , I've never used the PickCount before so will give it a try, and report my findings back here.
B
46
S
23
G
31
Posts: 693
Reputation: 20,637

Post » Sun Aug 30, 2015 4:32 pm

@jeebroniz

in the Add Action window for an object, down at the bottom is a Z-order section.
you can move an object to the top or bottom, or move it next to another selected object (in front or behind).
Those functions should give you the ability to easily order your objects any way you want, The For Each (Ordered) performs extremely quickly for me, so it could be some other factor that is killing your performance.
Every object has a Zindex value you can access directly to figure out its depth - there are lots of ways to make it work.

like I said above, the main trick is to avoid ambiguous situations when comparing one object to another of the same type ( object.Zindex > object.Zindex doesn't make sense because C2 can't tell which specific instance is which). So, you have to pick the first object by the type, and the second one by a family (so you end up comparing object.Zindex > familyObject.Zindex) those could be any two instances you want, but now C2 knows which one is being compared to another of the same type,
B
97
S
34
G
20
Posts: 438
Reputation: 17,790

Post » Mon Aug 31, 2015 5:48 am

@AllanR, sorry but I really don't know where to find the PickCount. I've created a really simple capx, hopefully you can take a look and show me how to set it up? Would really appreciate it.

https://www.dropbox.com/s/8x744t38ixrs3tk/Test01.capx?dl=0
B
46
S
23
G
31
Posts: 693
Reputation: 20,637

Post » Mon Aug 31, 2015 7:55 am

@rekjl

PickCount isn't found on any menu, but it is a property you can enter in expressions. You can use Object.count to see how many total instances there are of Object, and you can use Object.PickCount to see how many are currently selected.

We don't really need PickCount to do what you want, but I added it just to show you how to use it (by displaying the number in a text box).

I set up your capx the way I described above. I made it show if the piece you click on is blocked from being removed, and it highlights all the pieces above it... (if there are none then it removes the piece).

http://www.rieperts.com/games/forum/ZorderTest.capx
B
97
S
34
G
20
Posts: 438
Reputation: 17,790

Post » Mon Aug 31, 2015 12:02 pm

@AllanR, wow thank you! That was so informative! Haha it is great to learn something new. Again, thanks, much appreciated!
B
46
S
23
G
31
Posts: 693
Reputation: 20,637

Post » Mon Aug 31, 2015 3:25 pm

PickedCount and ZOrder are both common expressions. Most plugins have them you access their expressions list.
B
71
S
30
G
25
Posts: 984
Reputation: 19,503

Next

Return to How do I....?

Who is online

Users browsing this forum: matriax and 27 guests