GMS 2 How to recreate a depth value.

I hope this is the right forum for this.

I have some familiarity with GMS1 from my youth so I bought GMS2.

With my main aspirations being the creation of a psudo3D game which utilized the depth feature in the Drag&Drop.

I have seen some murmurings of a way to use a depth function within the GML.

Could someone please walk me through how to set up an easy way to revive this legacy feature through GML or scripts in a manner that lets me mostly stay within the DND?

I kinda wish there was a version of GMS1 that had the same export options GMS2.

I have experience with C++ but I kinda beat myself up when I code, so Game Maker, is like my vacation from that, so I don't get burn out while learning.

Again, I'm sorry if this is the wrong place for this question, I'm kinda new to the forum, and I'm not adverse to a little scripting or programming, I just would like to not stay doing that the whole time.

My question is: "what is the way to create a global depth parameter that my objects in the DND can use to determine how they overlap with one another, without me having to have a predetermined number of layers."

(I kinda wish layers and depth were both seperate check boxes within GMS2 for how to control Sprite overlap within a room, but... ...wishes are wishes...)
 

KiD_Rager

Member
I usually state the depth in an object's STEP event:

GML:
depth = -y;
If the object is never meant to move (e.g. a tree, wall, etc), then put it into the CREATE event for said object instead.

By setting depth to -y, the object will be layered higher than any object with coordinates smaller in y-value. Since we know that the greater a negative depth is the higher up in layer it will go, having it in the STEP event ensure that a player object, for example, can hide behind a treetop and yet be in front of its trunk depending where the player is located in the game. Adding collision masks to the sprites will also help you better define how the previously mentioned effect will look on a more detailed level.

This is better than changing the depth field in the object settings because what happens when we decide to add more object in the future? The -y depth check will be a life saver.
 
I usually state the depth in an object's STEP event:

GML:
depth = -y;
If the object is never meant to move (e.g. a tree, wall, etc), then put it into the CREATE event for said object instead.

By setting depth to -y, the object will be layered higher than any object with coordinates smaller in y-value. Since we know that the greater a negative depth is the higher up in layer it will go, having it in the STEP event ensure that a player object, for example, can hide behind a treetop and yet be in front of its trunk depending where the player is located in the game. Adding collision masks to the sprites will also help you better define how the previously mentioned effect will look on a more detailed level.

This is better than changing the depth field in the object settings because what happens when we decide to add more object in the future? The -y depth check will be a life saver.

I'll need to look up how to use the step event, which I'm okay with. Otherwise I'll probably put it in the wrong place.

The version of GMS1 I'm used to was the free trial that came with a book.

So... never got to use the scripting IDE in any GMS. Equal parts tentative and excited.
 

KiD_Rager

Member
I'll need to look up how to use the step event, which I'm okay with. Otherwise I'll probably put it in the wrong place.

The version of GMS1 I'm used to was the free trial that came with a book.

So... never got to use the scripting IDE in any GMS. Equal parts tentative and excited.
Very easy!

First, make sure an object is created. From there, click Add Event > Step > Step.



Then you'll open the Code Editor. This is where you add the code snippet I explained earlier.



And there you go - all done. Repeat this procdure for any other objects. Since most of your objects will be static, do the above but instead of the STEP event, toss into the CREATE event. Then when you place these objects into the Room Editor, where you add them will determine their depth automatically.

If you want to check the collision mask of the sprite settings, just click into your sprite and hit Collision Mask.



In my case, my collision mask is my entire sprite, Might be okay for your player object depending on your needs, but suppose you want a static object like a sign or something.



Here, my collision mask is smaller. The dark opacity represents where my collision box will be for the sign. With the depth snippet I add in for both objects, I can make that "back and front" effect happen. (Note: I made a mistake in the image - the origin should be the center of the sprite [16 x 16] to better illustrate the example but eh you know now, haha).

The reason for that last comment was because the origins of the sprite makes a different on what depth the object has. The effect will still take place but might clip parts of a sprite that I don't want to happen (like the player's foot sticking in front of the sign but the rest of the body behind it). You will likely have to play with the collision masks for each object and see what works best for you.
 
Top