Going in front and behind objects?

  • Here's what I'm trying to do: I want to make it so that the player object is displayed in front of a certain object, when it's below it and behind the other object, when it's above it, in order to create a simple illusion of depth.

    In Game Maker each instance of an object has a Depth variable, so there I could just set it to the Y position. In Construct, however, there's no such thing. There's the Z Elevation, but changing it also scales the sprite and I don't want that.

    I tried various methods like checking if the player object is overlapping with some other object and if its Y is Greater or equal to the other object's, but it doesn't work. So how exactly do I do this in Construct?

    Thanks!

  • You can move an object between the layers or change the Z position on the current layer (even against another object).

    Check the Z Ordering section: https://www.scirra.com/manual/132/common-actions

  • You don't understand. The problem is not which actions to use. The problem is that Construct doesn't seem to differentiate which instance of the object the player is in front of or behind. Let's say we have two palm trees on the screen, with one being slightly below the other one. The player overlaps with the higher palm tree and is below it. However the player object is not being drawn in front of the tree, but behind it, probably because Construct checks the Y position of the other tree, which is below the player object and therefore in front of it. So the same settings are being applied to every other instance of the palm tree object. I'm trying to make it so that it doesn't do that.

  • Many people made isometric games with C2. With such games z-ordering manipulation is a must, and they succeed so I am sure that everything is possible.

    You can do any action on an instance or on an object (all instances) it's just a matter how you grab your SOL.

    But I agree - I don't understant what's exactly the problem you describing.

  • Hi Bio,

    There are a lot of tutorials and different methods that address the problem you are describing. Here is one example that I like - https://www.scirra.com/tutorials/4981/s ... den-player

  • Here's a solution you can try:

  • Sorry for replying late. I'm afraid to say these methods didn't really work :/

    The tutorial example doesn't work, because I don't want the player to be displayed at all when passing behind objects.

    The method by Destitute doesn't work, because the actions, once again apply for all instances of an objects and this creates glitches, when the player passes around multiple layers of objects. For example: if the player is slightly behind one object, but also slightly in front of another object, the player object will be displayed behind both objects.

    Does anyone have any other solutions?

    Thanks.

  • The simplest is to put all the objects you want to z sort in a family (player, trees, walls, enemies). Then use a a for each ordered condition.

    for each family1 ordered by family1.y ascending

    --- family1: move to front

  • Just change the blend mode so that your source is completely blocked instead of atop for the silhouette.

    https://www.scirra.com/manual/146/effects

    I think the one you want is Destination Over, but I'm not 100% sure. Quick experimentation will help you find the correct effect.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sorry for replying late. I'm afraid to say these methods didn't really work :/

    The tutorial example doesn't work, because I don't want the player to be displayed at all when passing behind objects.

    The method by Destitute doesn't work, because the actions, once again apply for all instances of an objects and this creates glitches, when the player passes around multiple layers of objects. For example: if the player is slightly behind one object, but also slightly in front of another object, the player object will be displayed behind both objects.

    Does anyone have any other solutions?

    Thanks.

    I forgot to note, but my method doesn't work for you because all objects need to be on one same layer with the screenshot I posted, including the player.

    I used to have multiple layers (one for the player/enemies), objects above Link (such as the bridge overpasses inside of Hyrule Castle), below Link (switches) but I switched to one layer and started using family y ordering since in my opinion, having too many layers can cause unexpected (nature of bugs, half of the time, you don't expect them...) emergent problems later on and having most if not all objects on one layer makes them easier to debug, as long as the y ordering is initially done correctly.

  • The simplest is to put all the objects you want to z sort in a family (player, trees, walls, enemies). Then use a a for each ordered condition.

    for each family1 ordered by family1.y ascending

    --- family1: move to front

    I thought of it yesterday, saw this today and decided to try it. Tried it and it works. Huh. Thanks!

  • I'm having the same issue. I want my player to overlap an object but at the same time be behind an object thats one the same layer as the other object the player is in front of. For some reason all the other objects on that layer start switching from the front and back of eachother. For example i have my player behind the back of a house as well as a tree, making it look like the tree is above his head, but then i have another tree in the opposite side of the house that is now overlapping the house making it look like there is a tree on the roof of the house. How can I make it so the player is able to move behind the objectinand in front o while keeping them in the z order that i placed them in?

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