How do I Sort Container components order using values?

Get help using Construct 2

Post » Fri May 29, 2015 6:54 pm

I am making my own Z order system, its not working the way I had imagined it. However you cant physically manage a container using Z Order functions without first calling them from another object, so I was wondering if anyone had managed to do something like this? I am trying to manage them via values but its not working.

In fact this code doesnt work either:


If Group.Families Value < Group.Families Value

Group.Families Sort to Back of Object Group.Families

I mean it SHOULD work, but it doesnt? I dont understand. Even For Each loops doesnt fix this.

I want each object of the loop to check if its value is less than another member of its own families Z order value and then move behind it. It should work. And I even tried selecting the container from another object to move behind it, or above it based on its values however you still need to pick its components and move them to the layer value of the container HOWEVER the objects contained WITHIN the container lose their bloody family grouping when attached to it!
B
4
Posts: 33
Reputation: 266

Post » Sat May 30, 2015 5:02 am

I must be a tad tired as I can't follow that at all. I'll try again later... After which maybe some clarifying thoughts will have been posted.
B
13
S
5
G
4
Posts: 139
Reputation: 2,586

Post » Sat May 30, 2015 6:11 am

When you're comparing the variables, each object is comparing with itself.
To compare values of two different instances of the same object you either:
1 put the object type in a family so you can pick two separate instances independently. Ex:
For each sprite
For each family1
Sprite.value < family1.value

2 pick one object, save its value to a variable and then "pick all" and pick the other instance.

3 use the sprite(0).value expression where 0 is the instance number. That way you can access separate instances from the same expression. You will need to loop over each pair of instances though.


What I usually opt to do for sorting like you're doing is just to use a "for each ordered" condition which will do the sorting for you.

For each sprite ordered by sprite.z acending
--- sprite: move to front
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Mon Jul 13, 2015 5:15 pm

I actually figured out the equation its; WidthScreen * Object.Variable1 + Object.OtherFactor (whatever that may be, in this case it could be Y. or some other math)

As for what to do in C2 I did what you said r0j0hound, so thanks for confirming that. Its nice that there is atleast a built in way to do it with this engine. Not bad considering most engines cant handle that with a simple for each ordered command.
B
4
Posts: 33
Reputation: 266


Return to How do I....?

Who is online

Users browsing this forum: AndreasR, HellMax, tarek2 and 10 guests