How do I create a sense of depth (isometric sorta) [SOLVED]

Get help using Construct 2

Post » Sat Oct 29, 2016 4:27 am

Alright, it's not an isometric game but it's the best way for me to explain.

I simply want to make sprites that are closer to the bottom of the screen appear in front of those that are closer to the back.

So for example, let's say the player walks behind an enemy. The only issue is that if you placed the player after the enemy, it'll make it seem as though the player is walking on the enemies face - in other words the player would be overlapping the enemy even though they should be behind the enemy.

I've tried:

If Enemies(family) Y < Enemies(family).Y
--> Enemies(family) Z order Move in front of enemies.

If Enemies(family) Y > Enemies(family).Y
--> Enemies(family) Z order Move behind enemies.

Doesn't work. I assumed maybe it was because the events were applying the same thing to each and every enemy. So, I used 'For Each' after.

If Enemies(family) Y < Enemies(family).Y
For each Enemies(family)
--> Enemies(family) Z order Move in front of enemies.

If Enemies(family) Y > Enemies(family).Y
For each Enemies(family)
--> Enemies(family) Z order Move behind enemies.

Didn't work. I don't know where to go from this point, does anyone have any ideas?
Last edited by ChaoticShadow24 on Sat Oct 29, 2016 7:29 am, edited 1 time in total.
B
24
S
10
G
1
Posts: 153
Reputation: 2,660

Post » Sat Oct 29, 2016 4:59 am

https://www.scirra.com/manual/125/system-actions

"Sort Z order
Sort the Z order of instances of a given object according to an instance variable. This effectively removes all instances from their Z order, sorts them, then inserts the sorted sequence back in to the holes left behind. This means if the instances are spread across a range of layers, they will be sorted in the same Z order locations, maintaining the same order relative to other instances on those layers. Note this action is much faster than using an ordered For each with an action like Send to front/back, so this action should be the preferred way to sort the Z order of large numbers of instances."
Image ImageImage
B
168
S
50
G
164
Posts: 8,227
Reputation: 105,573

Post » Sat Oct 29, 2016 5:10 am

Can you please explain in what way I would use this to achieve what I want to do?
B
24
S
10
G
1
Posts: 153
Reputation: 2,660

Post » Sat Oct 29, 2016 5:20 am

You create an instance variable for the objects you want to sort.
When you want to sort them, pick them, and set the variable to their y value.
You then use the sort z order in the same event using that variable.

This will sort all those instances by their respective y values.

If you have diferent objects, place them in a family, and create a family variable.
Image ImageImage
B
168
S
50
G
164
Posts: 8,227
Reputation: 105,573

Post » Sat Oct 29, 2016 5:24 am

May I ask what you mean by 'pick them'?
B
24
S
10
G
1
Posts: 153
Reputation: 2,660

Post » Sat Oct 29, 2016 5:47 am

I mean get them into the selected objects list.
It can be as simple as:

>every tick, sprite set myvariable to self.y
>-system sort zorder by myvariable

But obviously you only want to pick the objects you want sorted.
Image ImageImage
B
168
S
50
G
164
Posts: 8,227
Reputation: 105,573

Post » Sat Oct 29, 2016 7:11 am

Okay cool! Looks like I got the hang of it, it works flawlessly. Before I'm done, I'd like to confirm something first!

Since I want both enemies and the player to be sorted, the most compact way of doing that would be to make a ZOrder family and put in all the objects I want to be sorted into that family, and assign the variable to that, rather than doing this ZOrder thing for every single family that needs it, right? Are there any problems that could possibly pop up as a result of that, or am I golden?
B
24
S
10
G
1
Posts: 153
Reputation: 2,660

Post » Sat Oct 29, 2016 1:58 pm

Sounds fine.
Image ImageImage
B
168
S
50
G
164
Posts: 8,227
Reputation: 105,573


Return to How do I....?

Who is online

Users browsing this forum: Bro7hers, ketramtu18 and 10 guests