# Several Depth For One Single Object [SOLVED]

Z

#### Zephyr Schwarzwolf

##### Guest
Hi everyone !

Oooook, that one is VERY tricky and I have no idea how to do that but I'm going to try my luck if someone has a solution !
In my game, I have two type of tiles for my graphics.
Some ones are flat : The floor, aaaand anything else which is flat and set on the floor.
Other ones have a height : Walls, the player, all NPCs, most of visible objects, etc...

So. Here's what I would like to do :
For objects that have a height, set : depth = object.height
Yes, the aim is to attribute several depth on a single object :
- depth - 1 on the first line pix
- depth - 2 on the second line pix
- depth - 3 on the third line pix
- etc...

I know it's a lil fetched to do a system like this one but it would be a PERFECT depth system for what I want to do. I still have some issues with the order with which my layers display (mainly with collisions). It would solve all these problems.

First of all, is it possible ?
If yes, how ?
or else, do you have a better solution ?

#### TheouAegis

##### Member
Base depth on the lowest row of the sprite or tile. If a sprite is 16x24 and the lowest pixel is at y:128, and you have a tree that is 32x96 with its lowest point at y:140, it doesn't matter what coordinate the rest of the pixels are - the tree will always be on top.

Z

#### Zephyr Schwarzwolf

##### Guest
I know, but is there a way to change that ? A way to have a "base" depth on the lower pixel and increase the depth in the image til its upper pixel ?

#### Nocturne

##### Friendly Tyrant
Forum Staff
I know, but is there a way to change that ? A way to have a "base" depth on the lower pixel and increase the depth in the image til its upper pixel ?
Short answer: No. In a single object you cannot draw things over multiple depths.

Long Answer: Yes. You can create your own draw system based on priority queues or something like that and then have a controller do all the drawing based on the priority (depth) of the thing being drawn. This is very complex and (in my experience) usually overkill. Alternatively, you could make a parent object for the thing to be drawn, then make different child objects to draw each part and assign each child a different depth. You can then check collisions and other things based off a check with the parent object (although if the game is large then the extra overhead of instances could kill your FPS...).

Z

#### Zephyr Schwarzwolf

##### Guest
Oh, I see. This seems not to be a good idea, so. Thank you Nocturne ! I think I'm going to try another system that can approach things as naturally as possible (but simplier).

##### Member
Oh, I see. This seems not to be a good idea, so. Thank you Nocturne ! I think I'm going to try another system that can approach things as naturally as possible (but simplier).
I'm not positive this is what you're looking for, but I think that Z-Tilting might get you what you want. https://www.yoyogames.com/blog/458/z-tilting-shader-based-2-5d-depth-sorting

However, much like what Nocturne said, when I first read this it seemed more complicated that what I needed for a similar issue. Although I don't think that a controller with a priority queue is really that complicated. There's also a free asset: https://marketplace.yoyogames.com/assets/5360/fc-s-depth-system.

Z

#### Zephyr Schwarzwolf

##### Guest
I'm not positive this is what you're looking for, but I think that Z-Tilting might get you what you want. https://www.yoyogames.com/blog/458/z-tilting-shader-based-2-5d-depth-sorting

However, much like what Nocturne said, when I first read this it seemed more complicated that what I needed for a similar issue. Although I don't think that a controller with a priority queue is really that complicated. There's also a free asset: https://marketplace.yoyogames.com/assets/5360/fc-s-depth-system.
That's EXACTLY what I'm now opting for. I converted my "vertical" tiles into objects to set a "depth = - y". I intend to set a 32 depth shift at each level, as planned at the beginning.
It works great for my "statics" objects, but when I try to set the same code on my player object, the depth doesn't change. It stay at the y first position !
Here's my code :
Code:
``depth = y - room_height;``
It doesn't work when I add "vspd"... Do you know what's going wrong ?

##### Member
That's EXACTLY what I'm now opting for. I converted my "vertical" tiles into objects to set a "depth = - y". I intend to set a 32 depth shift at each level, as planned at the beginning.
It works great for my "statics" objects, but when I try to set the same code on my player object, the depth doesn't change. It stay at the y first position !
Here's my code :
Code:
``depth = y - room_height;``
It doesn't work when I add "vspd"... Do you know what's going wrong ?

Without seeing all of the code it's very hard to say as there are a bunch of similar system that are different enough. Still, it sounds like maybe that code isn't in the step event? Or maybe you're drawing still drawing it in its own draw event? Also, why y - room_height? Wouldn't that mean that objects at the top of the screen are drawn over objects below them?

Z

#### Zephyr Schwarzwolf

##### Guest
Without seeing all of the code it's very hard to say as there are a bunch of similar system that are different enough. Still, it sounds like maybe that code isn't in the step event? Or maybe you're drawing still drawing it in its own draw event? Also, why y - room_height? Wouldn't that mean that objects at the top of the screen are drawn over objects below them?
Gosh, you're right for that "y - room_height" ! (These inverted axis are sooo confusing for me) The problem is that I'm trying to combine the idea of my current depth system to that new one. I'm gonna need to be organisated ! Ahah
About the code, I wrote it in the create event (That's here my origin depth was set before I decided to change it) and, you're right, I probably oughta set it in the step event !
I'm gonna try out that then come back to tell if it was the right thing to do ! Thank you !

Z

#### Zephyr Schwarzwolf

##### Guest
That's almost perfect ! (Thank you once again)
A last thing, in the room editor, when you select a layer, you can attribute a depth to that layer. How to handle this value in the code ? (I'm searching for its name !) I tried "layer.depth" but it considers "layer" as a variable...

Last edited:
Z

#### Zephyr Schwarzwolf

##### Guest
PERFECT ! I used the layer_get_depth() function. It works perfectly ! Thank you very much !