• 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!

GameMaker tiles & depth

Z

zendraw

Guest
how do you apply depth to tiles so that player can go behind them when his bottom is above theyr bottom? and infront when his bottom is below theyr bottom.

basicly adding the -y depth thing, or similar. only way i see is making diffrence betwean layer`s depths the same as the grid and making as meny layers as there are rolls on the grid.
 

curato

Member
There are some more advanced tutorials on ways to do it but the easiest way would be to split the top and bottom into separate tiles and set the collision such that the bottom isn't passable and the top is and put the top on a layer above the player and bottom below. Just have enough collision to keep you from passing from the bottom to the top. Otherwise, you need to get somewhat dynamic with your depth sorting.

I have also seen some people use a shader or a sprite shift to show like a outline that the player is behind something so you see where it is. If that makes since to your project that may be another low overhead option.
 
Z

zendraw

Guest
that one is viable if the player sprites dont clip into the building, and im pretty sure these will clip in. can you share these advanced tutorials.
 
I have long been a Tile management person since the time I read that tiles were a lot less heavy on machine resource than objects but that's back in GM 8.1. I don't know how your game is setup, but I think you have 2 options, 1 that keeps an array of the dynamic depth tiles which will keep track of each tiles ID, basically a script at room creation that looks for all tiles of a certain depth and keeps their IDs and Y values in memory. Then in your tile controller's step event, check for your character's Y position and reduce the depth of all tiles that have a lower Y value than your character.

The other option would be to dynamically change your character's depth depending on your Y value. This would also require a controller looping all the tiles in the room ONCE at room creation to change their depths depening on their Y positions. But that would necessarly require your other tiles that NEED to stay under and above to have very high depth values to make sure your character always stays over or under those un-dynamic tiles. If it wwould be me, I would choose this option over the first one because it requires you to only change 1 thing in your character's step event based on it's Y position while as the other controller option, to what I would guess, might requires more resources on the machine as it's constantly looping an array, but I am not the best to compare about machine resources, I just tend to try and avoid looping when unecessary.

Other members may have other ideas. I don't adhere to splitting the top and bottom because it will add so much time in creating your rooms unless you would have a controller replace the single tiles and seperate the with up and down portions for you.
 
Combine a few things:
Where possible, draw things at layers under and above the instance layer the player object is on.
(let's call the player layer "Instance_Player")

Now, certain things might need a bit more adjustment as to when the player appears in front/behind it.
I have a VERY simple trick for you that I'm using all the time,
but it requires your layers to be separated by large numbers in their depth. Just go by the millions (or even a higher power of 10 to be sure):

layer depths in room editor
--------------------------------------
top layer = 0
next layer = 1 000 000
next layer = 2 000 000
Instance_Player layer = 3 000 000
next layer = 4 000 000
and so on.....

Simple enough.

Now you just need objects that have a sprite.
Objects that don't move are static, put this in their create event:
Objects than can move, like the player, are dynamic, put this in their step event:

GML:
depthspecific = 0;
depth = layer_get_depth("Instance_Player") - (((y-depthspecific)*room_width) + x);

the variable depthspecific is just a number you can use to finetune (negative or positive) where depthsorting starts in the vertical pixels in the object's sprite.

This will cleanly sort objects from top to bottom, and left to right, causing perfect overlaps.

Really, no datagrids needed, no "trying to get my tilesets juuuust right", no special long code and data sorting needed.

This basically sorts objects by their y value, followed by their x value, in a single number per object.
It creates a single depth number per object, a quite large number, but in it you'll find the y and x values separated by a bunch of zero's, in a way that
equalizing it to their depth makes it work in a neatly sorted way.

1 042 005 for example
that's 1 number for both the x and y coordinates. The "1" million is needed for the number to remain large,
and 042 005 are basically an x and y value, only separated by their power of 10.
Sorting with that? Well there you go: as easy as it can get.
 
Last edited:
Z

zendraw

Guest
there is no depth setting function for tiles in game maker 2, which is why the question.
 
Z

zendraw

Guest
does yoyo have some official tutorial on how to deal with this? game maker being sprite based and top down being one of the main genres it shuld be vital to have such a tutorial.
 
Top