How do I pick one of several objects and make the Z order change?

0 favourites
  • 3 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • Hey everyone!

    Have been sitting here trying to solve a problem but I can't figure it out. I am building a tower defense game where I have a laser tower. I can build this laser tower on several building spots and if you build it next to another tower then occasionally the laser overlaps the tower next to it. When the laser then follows the object it is shooting at, it appears under the whole tower (see attached pic).

    I want the laser to change Z order so that it is above the tower it is overlapping that is not a part of its container.

    I have tried several solutions. I have an instance variable that I assign on creation so the laserID is set to the tower cannon UID, and I was thinking that if the laserID is not equal to the tower1cannon UID then on overlap it would put the laser above that cannon (see attached pic of events). But I can't figure it out. I have only tried to solve this for the same tower type.

    My dream scenario would be to find a solution that solves this problem so that the laser won't go under any of the 5 towers that are buildable in the game.

  • Picture of my try to pick the right object.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Put all your sprites from which you want to Z-Order into a Family.

    Add A Number Instance Variable To the Family, call it SortYOrder.

    Finally add the code below to sort Z-Order according to it's Y Position.

    To sort the reverse as in backwards, Sprites Set SortYorder to -sprites.y

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