Making a Z order system: Easy

15

Features on these Courses

Contributors

Stats

4,130 visits, 5,676 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!
  • 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

  • I don't understand why adding an instance to the z order family is necessary to use the system action. I am probably going to have a follow up question to your answer, if you don't mind.

    • That is because the system action doesn't take an expression, but an instance variable, so we must use one.

      Sure, ask any question you have.

  • Load more comments (2 replies)