Compare the Z order between two instances?

0 favourites
  • 11 posts
From the Asset Store
Footsteps SFX Two contains 450 sounds of steps and jumps on different surfaces.
  • 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?

  • 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.

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • 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,

  • 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

  • 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

  • AllanR, wow thank you! That was so informative! Haha it is great to learn something new. Again, thanks, much appreciated!

  • PickedCount and ZOrder are both common expressions. Most plugins have them you access their expressions list.

  • Magistross, thank you for that. Haha ya, I should really access the expressions list more often to learn new expressions. Thanks for the heads up.

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