Making a Z order system: Easy

16

Features on these Courses

Contributors

Stats

4,233 visits, 5,818 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 15 May, 2019. Last updated 4 Jun, 2019

In this tutorial I will go over the simplest way to make a Z sorting system. This system is very simple to write and to understand.

The idea

On every frame, we want to reorder every object so they draw from top to bottom. Therefore the z order will depend on the Y coordinate of the object.

How to do that

Create a family that will contain every object that will get ordered. Let’s name it ZOrder.

Once that is done, this is what we want to do:

However, this is not the best way to do it. Here we do a for each loop on every tick, which can prove to be very slow when dealing with lots of objects. Instead we can add an instance variable to the ZOrder family, and name it “order”. Once that is done we can use the premade system action for reordering objects.

That's it. For the simplest z order system, all you need are these 2 actions.

  • 10 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • or, set the Z to that of the Y position :)

    • If you mean the z elevation, you can also do that :)

      Just be sure not to set it to values too big or you might have an unwanted perspective effect (or maybe it is wanted and in that case it's great)

  • I would recommend to add a "ZOrder Is on-screen" condition.

    It helps greatly with performance and has no disadvantages as long as it's only a visual thing and not part of the collision system, like in the later tutorials of this course.

    • I will have to say thats wrong. "ZOrder is on-screen" checks for ANY ZOrder object on the screen, and then sorts ALL of them anyway. I went with "Pick by comparison: distance between ZOrder and MC <3000" and saved 5% of CPU load, while simple on screen condition did not do anything at all

  • Mi Amor. Thank you <3

  • Is there any c3p available?

  • wow nice trick, thanks

  • Load more comments (2 replies)