0 Favourites

How do I create a sense of depth (isometric sorta) [SOLVED]

  • Alright, it's not an isometric game but it's the best way for me to explain.

    I simply want to make sprites that are closer to the bottom of the screen appear in front of those that are closer to the back.

    So for example, let's say the player walks behind an enemy. The only issue is that if you placed the player after the enemy, it'll make it seem as though the player is walking on the enemies face - in other words the player would be overlapping the enemy even though they should be behind the enemy.

    I've tried:

    If Enemies(family) Y < Enemies(family).Y

    • -> Enemies(family) Z order Move in front of enemies.

    If Enemies(family) Y > Enemies(family).Y

    • -> Enemies(family) Z order Move behind enemies.

    Doesn't work. I assumed maybe it was because the events were applying the same thing to each and every enemy. So, I used 'For Each' after.

    If Enemies(family) Y < Enemies(family).Y

    For each Enemies(family)

    • -> Enemies(family) Z order Move in front of enemies.

    If Enemies(family) Y > Enemies(family).Y

    For each Enemies(family)

    • -> Enemies(family) Z order Move behind enemies.

    Didn't work. I don't know where to go from this point, does anyone have any ideas?

  • "Sort Z order

    Sort the Z order of instances of a given object according to an instance variable. This effectively removes all instances from their Z order, sorts them, then inserts the sorted sequence back in to the holes left behind. This means if the instances are spread across a range of layers, they will be sorted in the same Z order locations, maintaining the same order relative to other instances on those layers. Note this action is much faster than using an ordered For each with an action like Send to front/back, so this action should be the preferred way to sort the Z order of large numbers of instances."

  • Can you please explain in what way I would use this to achieve what I want to do?

  • You create an instance variable for the objects you want to sort.

    When you want to sort them, pick them, and set the variable to their y value.

    You then use the sort z order in the same event using that variable.

    This will sort all those instances by their respective y values.

    If you have diferent objects, place them in a family, and create a family variable.

  • May I ask what you mean by 'pick them'?

  • I mean get them into the selected objects list.

    It can be as simple as:

    every tick, sprite set myvariable to self.y

    -system sort zorder by myvariable

    But obviously you only want to pick the objects you want sorted.

  • Okay cool! Looks like I got the hang of it, it works flawlessly. Before I'm done, I'd like to confirm something first!

    Since I want both enemies and the player to be sorted, the most compact way of doing that would be to make a ZOrder family and put in all the objects I want to be sorted into that family, and assign the variable to that, rather than doing this ZOrder thing for every single family that needs it, right? Are there any problems that could possibly pop up as a result of that, or am I golden?

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Sounds fine.

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