How do I Sort the Z Axis by the Y co-ordinate?

Get help using Construct 2

Post » Thu Apr 06, 2017 9:42 am

I have had this question answered before a year ago but the link that was put in the answer has no expired.

I also want to expand on this by no only sorting sprites order in a layer but also a tilemap. Is that possible?
Thanks
B
5
S
1
Posts: 35
Reputation: 445

Post » Thu Apr 06, 2017 10:23 am

I had done this before, but with sprites only (I didn't use tilemap on my project at that time).

You can do like this:
Code: Select all
for each [object] order by [object].Y descending {
   [object] move to top of layer
}
B
33
S
10
G
2
Posts: 46
Reputation: 3,063

Post » Thu Apr 06, 2017 10:54 am

Thanks, I don't think it will work for a tilemap though as they can't be in the same family as a sprite
B
5
S
1
Posts: 35
Reputation: 445

Post » Thu Apr 06, 2017 1:13 pm

How about storing all related object's UID in an array, sort them, then pick one by one and set it to top?

Probably 2 dimensional array, y(0) = Y coordinate; y(1) = object type ("sprite"/"tilemap"); y(2): UID. This way, you can sort by X axis and get the sort by Y coordinate.

Code: Select all
first store each UID in array;
sort array by X axis;
for each array x element {
   if( array.at(array.curX, 1) == "SPRITE") {
      pick [sprite object] with UID = array.at(array.curX, 2);
      move object to top of layer;
   } else {
      pick [tilemap object] with UID = array.at(array.curX, 2);
      move object to top of layer;
   }
}
B
33
S
10
G
2
Posts: 46
Reputation: 3,063


Return to How do I....?

Who is online

Users browsing this forum: vegapomme27 and 10 guests