How to not get buggy object layer sorting when having some objects that should overwrite layer sorting?

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • I am making a game with a sort of semi iso/top down view where characters that move in the Y plane and objects need to be sorted properly in front or behind each other depending on their position. The Layer Object really comes in handy with the Decreasing Y Sort but it only works as long as no other object is sorted manually. However I need to also do some manual sorting, my main character is made up of parts like head and arms and the head and arms are obviously placed above the feet in the Y plane so with just the Decreasing Y sort they would be behind the actual body of the character. And I can't just adjust their hotspot y position because the head and arms also are using angle to adjust their angle based on their hotspot position that needs to be placed correctly for the angle to be rotating around the right spot (like the shoulder joint on the arm). I have uploaded a simplified example of the issue I am having.

    So basically how can I sort through all objects with Decreasing Y Sort and still have some objects that overwrite this sorting but at the same time does not cause bugs and flickering in the sorting? As of now I get this wonky buggy behavior with objects on the same Y position flickering in and out instead of being shown stable.

    Please login to see this attachment.

    Please login to see this attachment.

  • You can also sort by an alterable value - so if you assign each object an alterable value that's something like their Y position + (X position as a smaller number)

    Please login to see this attachment.

    There's two versions in there, one which sorts both via Y position and left to right, and one which sorts Y position and distance from the middle of the screen (which will probably look better depending on where you intend for the player's focus to be)

    Just note that the sort by alterable value action that the layer object uses will apply this to *all* objects on that layer - so you might want to use an alterable value that shows up further down the list (rather than alterable value A) depending on what youre doing with the other objects

  • You can also sort by an alterable value - so if you assign each object an alterable value that's something like their Y position + (X position as a smaller number)

    Please login to see this attachment.

    There's two versions in there, one which sorts both via Y position and left to right, and one which sorts Y position and distance from the middle of the screen (which will probably look better depending on where you intend for the player's focus to be)

    Just note that the sort by alterable value action that the layer object uses will apply this to *all* objects on that layer - so you might want to use an alterable value that shows up further down the list (rather than alterable value A) depending on what youre doing with the other objects

    Ah nice thanks this is much better! Is it a way to not sort them so "evenly" in the x position though? It looks a little bit odd with them having such perfect sorting in the x plane, is it possible to have that appear more "random" ?

    Steam games: Please login to see this link.

  • You could assign each object a random value (e.g. rrandom(0,1000) and add that to to the Alterable Value A. You could even replace the X coordinate stuff with just a random value assigned at creation, as long as its lower than whatever you multiply the Y value by

  • You could assign each object a random value (e.g. rrandom(0,1000) and add that to to the Alterable Value A. You could even replace the X coordinate stuff with just a random value assigned at creation, as long as its lower than whatever you multiply the Y value by

    I tried to do it but I think there is something I am not getting because it did not work out properly and the character is no longer ordered properly (attached example)?

    Please login to see this attachment.

    Btw I know I have used rrandom before but cant remember what it does, what is the difference between random (1000) and rrandom (0,1000)?

  • Ah, instead of

    ( Y( "Group.Friends" ) + ( 1.0 * Alterable Value B( "Group.Friends" ) ) ) * 1000

    Try;

    ( Y( "Group.Friends" ) * 1000 + ( 1.0 * Alterable Value B( "Group.Friends" ) ) )

    ---------------------------------

    rrandom(x,y) just generates a random number between X and Y, so rrandom(500,1000) will give you a random number from 500-1000.

    random(x) will give you a random number between 0 and X - rrandom(0,X) would be the same thing.

    I tend to use rrandom out of habit just so if I'm quickly skimming over my code I can always clearly see what the bottom of the range should be

  • Ah nice thank you! Btw do you know if this can be used with any frame size or would one have to increase the number (1000) based on the size of the frame? Say if having a frame that is 100000x100000 etc?

    Or is the number 1000 more dependent on the amount of objects? Could I use 10000 with the same effect to be even more sure that no one gets the same number?

    Ah I see rrandom makes sense if the first number is above 0 so that confused me a bit since it used 0.

    I actually see that rrandom (0,5) gives a number between 0 and 5 so that is nice since random (5) gives a number between 0 and 4 so rrandom seems more clear of the actual range of the number up to 5 for example.

    Steam games: Please login to see this link.

  • Ah nice thank you! Btw do you know if this can be used with any frame size or would one have to increase the number (1000) based on the size of the frame? Say if having a frame that is 100000x100000 etc?

    Or is the number 1000 more dependent on the amount of objects? Could I use 10000 with the same effect to be even more sure that no one gets the same number?

    As long as the final calculated number is below fusion's limit (a little over 2 billion I think) it should be fine. Unless you have thousands of objects with the exact same Y position on screen at the same time then there's probably no need to increase the number

  • As long as the final calculated number is below fusion's limit (a little over 2 billion I think) it should be fine. Unless you have thousands of objects with the exact same Y position on screen at the same time then there's probably no need to increase the number

    Ah I see, what about if I have around lets say 3000 objects would using the number 1000 still be enough?

    Steam games: Please login to see this link.

  • It's more about how many objects are on a single "row":

    Linky's example is what is known generally as "packing a 2D array into a 1D array" (well, or many other variations of that phrase).

    Here's an article about it with pretty easy to read code in Python: Please login to see this link.

    Basically it boils down to:

    1) Know how many things ("columns") can occur in each "row" (in this case, the "row" is a single exact Y pixel-position); if you need 1,000 objects on one "row", you need to define the width to be 1,000 "columns"). This width is does not have to be width of the screen (although this is easiest and is what I've outlined below more or less; if you don't need 100% accuracy you can use fewer values by dividing the width of the screen by 10 for instance, but the rest of the math gets a bit trickier).

    2) Define the length of the final array (this isn't needed in the pure numerical example in your case, but it is helpful to know what the highest possible value would be): this is always the number of rows * the number of columns in each row.

    3) Find the range of positions that represent the row for a given object:

    Y-position-of-object * width
    which would be:
    Y( "Group.Friends" ) * 1280

    4) Add the X index to this position for a given object:

    Y( "Group.Friends" ) * 1280+ Alterable Value B( "Group.Friends" )

    For example:

    1) You need to represent up to 1,280 objects on a row (this is how many horizontal pixels there are).

    2) There are 720 vertical pixel positions in a 720p resolution screen.
    This means the maximum value for an object is 921600.

    3) For an object at X=123 and Y=420, the row "block" is:
    420 * 1280= 537,600

    4) And the X index is 123, giving a final sort number of:
    537,600 + 123 = 537,723


    Another object might be at X=574, Y=420, giving:
    420 * 1280= 537,600
    537,600 + 574 = 538,174

    Which means it would be sorted "after" the first example object, and therefore drawn over it (if they are large enough to overlap).

    Linky correct me if I messed up anyway plz ;)

    [Edit: I did fix my math after remembering that you need to do more work to make the 2D array lower resolution than the full width of the screen.]

  • random(x) will give you a random number between 0 and X - rrandom(0,X) would be the same thing.

    Actually, there's a small difference. The second parameter in RRandom is inclusive.


    So Random(5) would produce one of: 0 1 2 3 4

    RRandom(0,5) would produce one of: 0 1 2 3 4 5


    Like marbenx, I usually prefer RRandom, and this is another reason why. Not only does RRandom show you the bottom of the range, it also shows you the top of the range more accurately than Random does.

    Please login to see this link.
    My Fusion Tools: Please login to see this link. | Please login to see this link. | Please login to see this link.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!