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

Question - Code Dynamic depth bug

M

mall0c

Guest
I have found some weird behavior in GameMaker during the making of my current game and need some advise on how to fix this.
I was able to reproduce it for a very simple case:
Consider a 2D topdown game where a player object can move through the room. Also, there are some tree objects.
Because I want my player to be able to pass before and behind the trees, I set the player's depth to -y every step and the trees' depth to -y on create. Everything works fine so far. But now I also call the "instance_destroy" function on some of the trees to remove them from the room after they have been created. When I move my player to the y position of a tree I have destroyed, the sprite will disappear. If I move one pixel up or down, it reappears. This happens every time I use a function like "instance_destroy" or "instance_deactivate...".
Do you have any idea why that happens and how I can fix it?

EDIT: Also, this only happens when the player moves upwards.
 

MarceloP

Member
Hello @mall0c,

Can you share a new project that only contains elements to reproduce this bug? I think this may be something else, since I've not experienced this ever, and I make a lot of games in the same fashion as yours.
 
I learnt this the hard way, it's not a bug. It's the way that game maker 2 handles depth sorting and drawing.

You need to use layers instead of depth -y otherwise you get flicker.

Your best bet is to have a parent object that draws the other objects all at once. At the start of a step put all the id's into a ds_list with their y position then loop through and draw them.

This is the only way you will eliminate that issue.
 
Top