Dynamic Z ordering

0 favourites
From the Asset Store
Firebase: Analytics, Dynamic Links, Remote Config, Performance, Crashlytics on Android, iOS & Web Browser
  • Construct needs to have something to sort your sprites by .

    So you need to assign an instance variable to your sprites like "ZPosition"

    then you have other events that will assign values to the Zposition variables for those sprites based on whatever is determining your z position.

    Then at the end you call the Sort Z Order (by instance variable)

    ascending descending would be handy but you can just do this yourself easily when calling by multiplying the variable by -1 if you want to swap it around.

  • I only kinda follow.

    ...I've created an instance variable for my object in question (GhostHunter).

    So far I have a no-condition event line with the two actions:

    (1) GhostHunter set instance variable ZOrder to round(Self.Y)

    (2) System Sort GhostHunter Z Order by GhostHunter.ZOrder

    Similar to the illustrations shared earlier on this thread, my GhostHunter character needs to appear behind other GhostHunters when it is "farther away" from the player (given the top-down/angled behind camera assumption). Thus, any GhostHunter that is lower on the Y-axis needs to appear "behind" other GhostHunter instances.

    If using a For Loop is inefficient (and so far ineffective per my efforts), I'm failing to understand how to make the Sort Z Order action useful. What do I do next or change given what I have so far??

  • Rhindon, it sounds like you have the needed steps, although you'll want to run that sort only every 0.1 seconds, and not on every tick. But is it not working for you?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • nacra - Well, if that's the case, I don't know what's wrong because any instance of my GhostHunter character that's atop another instance remains on top regardless of its Y-position on the layout. I should add that I don't change the GhostHunter instance variable at all. It's just there so that I can use the Sort action.

  • I only kinda follow.

    ...I've created an instance variable for my object in question (GhostHunter).

    So far I have a no-condition event line with the two actions:

    (1) GhostHunter set instance variable ZOrder to round(Self.Y)

    (2) System Sort GhostHunter Z Order by GhostHunter.ZOrder

    that sounds like it should work the only thing I can think of is maybe you need a "for each" ghost hunter at (1)

  • Rhindon, you might need to show us your relevant events, in case we can spot something.

    I did a quick test and saw Z-sorting work. Every 0.1 seconds it sets a sort order instance variable and then has the system sort by it.

    Edit: You should check that you have the first image point in the right location on each sprite. I think that's where the Y value is measured from.

  • I double, triple, and quadruple-checked everything - from event/action lines to image points. Everything lines up. I've verified the correct variables get referenced, and everything. I've tried

    A couple other details while you look this over...

    The actual GhostHunter objected is contained with the GhostHunterBody (right now their images look the same but "Body" is invisible at startup).

    The GhostHunter object is pinned to GhostHunterBody object. "...Body" controls all movement and contains 99.9% of all the variables. GhostHunter is using the ZOrder variable, though "...Body" also has the same variable (not used).

    https://www.dropbox.com/s/h2v1joiqaimjgoe/busters%20escape%20v8-3%20.c3p?dl=1

    The event line in question is 18 (Group "Enemy Z-Order").

  • So, watching those two ghost hunters in the red test area, I can see them properly sort sometimes, but not always. I wonder if it's related to the pinning and/or the body and hunter being separate sprites.

    What I did, that worked, was create a GhostHunter family, to contain the GhostHunter and GhostHunterBody, with a family instance variable for the z order. Sorting on that family instance variable seems to give a reliable visual.

  • AH! Okie dokey, then. I'll give that a shot and report my findings. Thanks for all your help, both of you!

  • *sighs* I don't know what's wrong, but even with a family, it's still not working. It occasionally sorts them correctly, but in the end, whichever GhostHunter is on the top of the layer stays on the top... It won't sort to the bottom, or rather below another GhostHunter, when it's at a lower Y-axis value than the others.

  • Rhindon

    HI mate I just had a look. I didnt solve your issue but I did find a way to make your game crash the C3 editor when swapping objects. So I am going to use it to raise a bug. I will try to have a look at the z sorting on the weekend, though it is hard to understand what you are doing with the different ghost bodies.

  • NetOne - Oh man, bugs always bugging ya. Such is the life of a programmer. Heh.

    Sorry for any confusion... I'll try to explain again with more clarity. Bear with me...

    As you see, there are multiple instances of the GhostHunter(Body) objects. (GhostHunter is the visual object that the player will see and GhostHunterBody is intended to be the object that does all the moving about and contains (most of) the behaviors, variables, and other stuff.)

    Taking into account that the "camera" angle (based on how things are drawn and now the actual camera/ScrollTo behavior), the visuals are that of top-down + slightly behind. Much like how Zelda: A Link To The Past was drawn on the SNES. With that visual angle, objects that are higher up on the Y-axis are technically "behind" or "farther away" (from the player's visual reference) than that of objects lower on the Y-axis. Assuming they're all on the same layer (they should be), objects that are "farther away" need to be drawn on the bottom of the layer or at least below objects that are "closer" to the player.

    So when one GhostHunter instance moves down on the Y-axis (closer to the player) they need to be redrawn on the top of the layer when "passing through" other instances of the same GhostHunter object. The current problem most of the time is that it looks as if certain instances on the top of the layer are literally on top of the other instances even though they should be behind them because they're higher up on the Y-axis.

    Further, the problem I'm having with the Z-order action line is that I don't know what the assumed sorting process is. Does it sort ascending or descending? I looked into the manual and couldn't find a clear answer. Is there a way to affect the sorting order? I'm guessing that the variable it's calling upon is used to calculate how it should sort or what it should sort, but again, I'm not finding a clear answer.

    Thanks for your time to help me work this out, too!

  • Yea, I think the issue is related to the fact that you need to sort everything including anything pinned to the ghost body, not just the ghost body and anything you are interacting with / overlapping. There are lots of people on here who have achieved what you are wanting so it is easily doable so don’t stress about it. In my own game literally everything you see on screen (Cyberstorm Devlog) (which is hundreds of items ) is z sorted every single frame and then on top of that all their additive overlays are z sorted on another layer every frame and there dosent seem to be much of a performance impact.

    Im at work (ehem just having a little coffee break surfing the construct forum….) but will hopefully have time to look weekend.

    Have you checked the Demonoir C3 demo? , im sure they would have to do the exact z sorting you are looking for there.

  • I was not aware of that demo. I'll surely have a look! Thank you for the suggestion.

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