• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Windows Clarity on layers & depth?

M

Major Cooke

Guest
I'm trying to wrap my head around the difference between layers and depth. It appears to me that layers are manageable while depth is not, being automatically determined by the engine, or something? I've read the manual but I'm still confused.

I know what a layer is, like Photoshop layers mind you, only the 'smaller' (more negative) the number is, the higher the draw priority over everything else. Is 'depth' supposed to be that number?

Yes, I'm confused on what the difference is between instance_create_[depth/layer] in that regards and what purpose is best suited for one or the other.
 

csanyk

Member
In old GameMaker, through GMS1.x, depth was a built-in instance variable that determined draw order. The first thing to be drawn is covered by the next thing. The deeper something is, the higher it's depth, the earlier it is drawn; the higher something is, the lower it's depth, the later it's drawn.

GMS2 deprecates this concept of depth, and replaces it with layers. Depth is kept around for legacy purposes, but layers are the preferred approach now.

Many 2D top-down/isometric GameMaker games use a technique of depth = -y to get things that are physically lower in the room on the y-axis to layer in front of things that they should be in front of, from a foreground/background standpoint. There's already a few topics on how this changes in GMS2.
 
M

Major Cooke

Guest
Ah, so depth is one of those old, now-unsupported features. Layer is the way to go then. Thanks!
 

rwkay

GameMaker Staff
GameMaker Dev.
Layers are the newer preferred way to control the drawing order.

We have kept the concept of depth (which you can use without thinking about layers if you want) as it is useful in some games and circumstances.

Behind the scenes when you use the depth variables we create a layer for you, as that is how rendering is now controlled - you can safely ignore this fact if you wish as it should have no bearing on what you are doing, but we tell you so that you can understand better what is happening underneath the hood. We are not deliberately trying to confuse the issue.

Russell
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Ah, so depth is one of those old, now-unsupported features. Layer is the way to go then. Thanks!
Not quite... :)

Depth is still valid... Imagine a top down game where you have a plane that drops a bomb... You want the bomb to "pass through" the layers below it to get to the "ground" layer. now to do this, you could have 50 layers and then switch it from one to the other, but it's much easier to simply do "depth += 1" in the step event. So, depth is still valid, albeit in a more specific circumstance. Now, the way it works is that when you use depth, GameMaker Studio 2 is still using layers, only instead of YOU assigning a layer for it, this is done automatically by GMS and the instance is on a "managed layer". You cannot use this layer, nor can you access it in code (the "layer" variable will return -1), but it's there. So CONCEPTUALLY, "depth" and "layer" are the same thing, only layers are more efficient and easier to use. :)
 
Top