Z-sorting (Explanation for Yann video)

Get help using Construct 2

Post » Mon Oct 28, 2013 3:19 am

Hey :)
I'm trying to catch up with the archived University of Reddit class that Yann and Kyatric did for Construct 2.

In this video, he is explaining Z-sorting through For Each (ordered):
http://www.youtube.com/watch?v=b2Ua_Rb4Kxo&feature=share&list=PL7GMuVXUsYnY8u61sW6ggXNyWOf47PfH7


I thought I was understanding what he was trying to achieve, but I evidently didn't. I thought that the sprites were going to be ordered in the Z axis according to their Y position in the layout.

But instead, the result is that when the player sprite is over the lower part of the tree sprites, he is in front of them and when he is in the upper part he gets behind them

I'm not understanding how this is happening, even after playing with the capx. Anybody care to explain, please?

Thanks!

https://dl.dropboxusercontent.com/u/23551572/C2Class/example/zSorting.capx
B
8
S
2
Posts: 39
Reputation: 1,492

Post » Mon Oct 28, 2013 3:54 am

In order for this way of sorting to work, all objects must be the same size.
Image ImageImage
B
169
S
50
G
169
Posts: 8,286
Reputation: 108,216

Post » Mon Oct 28, 2013 3:59 am

What I'm trying to understand is what's happening behind what Yann did, newt. I'm not sure what you meant with your reply.
B
8
S
2
Posts: 39
Reputation: 1,492

Post » Mon Oct 28, 2013 4:12 am

Never mind my previous comment, you've adjusted with hotspots.

Any way, the way it works is like a deck of cards.
The cards on the bottom of the deck would have a lower y value than the cards going to the top.
If you look at the for each you will see it has the ability to do the order ascending, that is to say low to high.
So the loop starts with the lowest y value object and sends it to the top of the layer, and then goes to the object that was just above that one, and then sends it to the top. That object is now visually on top of the first object.
This is repeated for all the objects so in the end you have basically stacked a bunch of cards in order.newt2013-10-28 04:14:49
Image ImageImage
B
169
S
50
G
169
Posts: 8,286
Reputation: 108,216

Post » Mon Oct 28, 2013 11:46 am

[QUOTE=wrongtarget]I thought I was understanding what he was trying to achieve, but I evidently didn't. I thought that the sprites were going to be ordered in the Z axis according to their Y position in the layout.[/QUOTE]

sorting by Y takes the origin point of the tree/player. As soon as the Y of the origin point of the player is lower than the origin point of the tree, the player is put behind the tree.

[QUOTE=wrongtarget] But instead, the result is that when the player sprite is over the lower part of the tree sprites, he is in front of them and when he is in the upper part he gets behind them[/QUOTE]

You should look again, as soon as the foot of the player sprite passes the foot of the tree, it is sent to the front/back of the tree, depending if the Y is lower or higher. There is no leeway like you claim.mindfaQ2013-10-28 11:47:15
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Mon Oct 28, 2013 9:18 pm

Thanks guys! With your help I think I've got the concept now. Cheers.
B
8
S
2
Posts: 39
Reputation: 1,492


Return to How do I....?

Who is online

Users browsing this forum: evillair, NumberOne, rbailey83 and 6 guests