• 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 Sprite appearing/disappearing with "depth = - y".

Ghiliam

Member
Hi everyone, I'm new of the forum, I hope I'm doing this right.
So I'm working on an RPG and I wanted to add some depth in the Overworld. I started using the most simple method of checking wheter the player's Y was higher or lower of the other instances's Y, and then change the instances's depth consequently.
But this method doesn't allow me to create an overworld that is complex as I wanted it to be, for example I can't put two trees or bushes so close that they are touching, because their sprites are gonna mess up.
So I switched to the "depth = -y" method, that do exactly what I want, but I'm facing this problem: when instances go "up" they flicker / seem to continuously appear and disappear. After some tests, I found that only at certain points they disappear, but is more like the engine is not drawing them on screen, as everything those objects does still happens. So they are here, but they are not drawn, if I am understanding this correctly.
Further tests revealed that this probably is a matter of how many instances are present on that depth and at that position, as I have tried to use "depth = 5000 -y" on the player, and that way stopped to appear/disappear. Then I used the same thing on the other objects on screen, and the problem came back. After this, I changed it to "depth = 2000 - y" just for the player, and it stopped appear/disappear, while other objects that stayed in the 5000 kept to appear/disappear.
I want to highlight the fact that this occur ONLY when objects are moving up/north/whatever you call the upper part of the screen. Moving in every other directions works perfectly.

So is there a way to make this thing working? Am I doing something wrong?
 

Ghiliam

Member
Sound like you set the depth somewhere else too. Maybe in a move script.
No I haven't, that "depth = -y" line is the only one that deals with depth.
It is in the Step event of the player and of the moving objects, and in the create event of the static objects.

There is a script that manage the player's movement, but it just modify the Y value of it.
 
M

MarceloP

Guest
You have to be a bit careful with objects on the same depth.

I'd do the following things in your case:
-> At first, I'd debug my character. Either create an key_release event and put a break on it, or print the depth of the object every step. Maybe use both solutions since on debug you can check all instances and their depths.
-> If all depths are correct or at least they seem to be, try to check any layers you have. As mentioned here by me, you can make any combinations of layers and depths BUT, you should always take good care of them because, right after setting a depth for an object, that object is moved to the so called "managed layer", which is not any of the ones you created and is managed by the game engine. So check your layers. Check if any layers don't mess with the depth your object can reach (for example, in a room with height 960, your object can reach depth -960). Oh, just a side note, objects created with "instance_create_depth" are always directly set to the "managed layer"
-> If everything is O.K. until now and you couldn't find the problem, I'd suggest you to literally press CTRL + SHIFT + F (search/replace on project) and search for "depth". There you should actually confirm is anything else is flickering your depth in any other situation or old code ( I know you just confirmed you are not, but a search is easier to check and maybe you missed something old on the code).
-> Finally, I'd simply try to check the sprite, direction and movement. One option is that the sprite is flickering, and has nothing to do with the depth system. Therefore, just disable any sprite changes or change it to a colored square, and walk it around. If that's the problem, great :D

If none of this work or have pointed any problems to you, I'd say you tell us so we can suggest other things and/or send us a small part of this object code, so we can see or point anything.
Good Luck :D
 
Is your depth value ending up greater than 16000 or less than -16000?

Last time I checked the docs, GMS 2 doesn't draw instances on layers with depths outside that range unless you force the draw depth.
 

Ghiliam

Member
You have to be a bit careful with objects on the same depth.

I'd do the following things in your case:
-> At first, I'd debug my character. Either create an key_release event and put a break on it, or print the depth of the object every step. Maybe use both solutions since on debug you can check all instances and their depths.
-> If all depths are correct or at least they seem to be, try to check any layers you have. As mentioned here by me, you can make any combinations of layers and depths BUT, you should always take good care of them because, right after setting a depth for an object, that object is moved to the so called "managed layer", which is not any of the ones you created and is managed by the game engine. So check your layers. Check if any layers don't mess with the depth your object can reach (for example, in a room with height 960, your object can reach depth -960). Oh, just a side note, objects created with "instance_create_depth" are always directly set to the "managed layer"
-> If everything is O.K. until now and you couldn't find the problem, I'd suggest you to literally press CTRL + SHIFT + F (search/replace on project) and search for "depth". There you should actually confirm is anything else is flickering your depth in any other situation or old code ( I know you just confirmed you are not, but a search is easier to check and maybe you missed something old on the code).
-> Finally, I'd simply try to check the sprite, direction and movement. One option is that the sprite is flickering, and has nothing to do with the depth system. Therefore, just disable any sprite changes or change it to a colored square, and walk it around. If that's the problem, great :D

If none of this work or have pointed any problems to you, I'd say you tell us so we can suggest other things and/or send us a small part of this object code, so we can see or point anything.
Good Luck :D

Thanks for the advices Marcelo! Let's see..
Well I have already tried the first using the debugger, and yes the depth value is changing as is should, even when the player object is not visible. As for the second one, I indeed have many layers divided in folders (mostly for organizing them, cause as you mentioned once the game started the depth ordering move them out of the layer I have put them into), and each folder is for a different thing: one for the GUI (always on top of everything), one for the things that are always above the player, one the for "ground" (the player and everything that it can interact with), then one layer for animations on the ground or under the water (waves of the water on the shore, fish ecc..) and a final folder for the "system things" (mostly to define with invisible objects the medium the player is moving on, if ground or water, if jump is allowed, ecc..). Speaking of the "ground" layer, there are like 6 of them and all on the same depth (tho I don't think is a problem, since [again] the depth ordering move them out of the layers as you said), but this is because I noticed that when I put too many objects in one single layer, editing slows down a lot, and thus my decision to create many layers for the ground on the same depth. This being said, the rooms I intend to create are very large for the majority, the one I'm working now is 3000x6000. How do I check if layers are messing with the depth my object can reach? (in this case -6000, which is well inside the -16000/16000 limits anyway)
Third point: Like the first point, I already searched for some "depth" that I may have forgotten or missed, but I got nothing, so I confirm that nothing outside that "depth = -y" line is modifying the depth.
Fourth point: like N°1 and N°3. Nothing new here too.

So for now my only concern are about the layers... but even testing in a small test room (something like 1024x768) with just one layer for the "ground" and way less objects than in the actual room, I get the same appearing/disappearing :,c

Is your depth value ending up greater than 16000 or less than -16000?

Last time I checked the docs, GMS 2 doesn't draw instances on layers with depths outside that range unless you force the draw depth.
Yes, right now I'm working on a room that is 3000x6000, so it perfectly fits the -16000/16000 specification.
 
M

MarceloP

Guest
Hello again @Ghiliam!

Could you send us the depths of your layers, and an scheme of how they're organized? I mean, it can be a screenshot, but the depths of those layers may matter. We have also to take care with layers on the same depth. As far as I know, if you have 2 instances that are on the same depth, GameMaker will use the creation order to decide who is in front of who but, after changing it to any other value, and then bringing it back to that depth GameMake simply puts that in the front of the drawing order (leaving it behind other things in the same depth).

One other suggestion would be to actually duplicate that room (one or more times) and start tearing all layers apart, removing almost all object (leaving 1 of each in a corner) and start removing layers and other stuff to check if its a problem (also making your main character's sprite an cube, with no animation and only simple moving events with no collision like: right_press -> x += 3).

You can also record a gif or small video of your problem, since we can identify something around your problem.
It really doesn't seems to be an engine problem, since I've been working with layers and depths for some time now, and haven't had any similar problem.
 

Ghiliam

Member
H
Hello again @Ghiliam!

Could you send us the depths of your layers, and an scheme of how they're organized? I mean, it can be a screenshot, but the depths of those layers may matter. We have also to take care with layers on the same depth. As far as I know, if you have 2 instances that are on the same depth, GameMaker will use the creation order to decide who is in front of who but, after changing it to any other value, and then bringing it back to that depth GameMake simply puts that in the front of the drawing order (leaving it behind other things in the same depth).

One other suggestion would be to actually duplicate that room (one or more times) and start tearing all layers apart, removing almost all object (leaving 1 of each in a corner) and start removing layers and other stuff to check if its a problem (also making your main character's sprite an cube, with no animation and only simple moving events with no collision like: right_press -> x += 3).

You can also record a gif or small video of your problem, since we can identify something around your problem.
It really doesn't seems to be an engine problem, since I've been working with layers and depths for some time now, and haven't had any similar problem.
Hi MarceloP,
after some more trial & error (for a total of 4 days of trial & error), I just gave up on using "depth = -y". I already did what you are suggesting, and I just had to accept that the problem is (I'm 99% sure at this point) indeed bounded to the high number of instances doing that precise thing.
If only the player or some objects do it, everything works fine, but over a certain number, the problem pops up inevitably, and get worse as the number of instances doing it rise.
I don't know why tho, probably some limits regarding the engine (I don't know if someone has ever pushed GM that much). On the bottom of the post you'll find a video of the problem. I was recording it in a zone without so much instances (usually there are at least 3 times what you see in the video, every layer has like 4-500 objects), again I don't know how much there are in the avereage GM game. Every flower is an instance (so they can bend when the player walks over them), and every tree is 3 instances (they're dividen in bottom, medium, and top, so that when the player walks behind them they can get all transparent except the base, when the player burn them the foliage can burn faster than the rest, and other silly CPU-eating details).
But aside from that, I just switched to the method used in the YoYo's Dungeon Demo (literally, I just imported their scripts :p). I was reticent to implement it, because looking at the code I though that it could have been too much heavy, but I found out that in fact it is working pretty much good. I just have to change some sprite offset to make it work right.
So, consider the case closed ahah, but if you're interested in further investigation on this depth=-y limit, I'll post a screen of the layers alongside with depths :)
 
M

MarceloP

Guest
Hello again @Ghiliam

That's very good to know that all worked out!
To tell you the truth, I'm really interested in this case, since I have a new game planned that may have a lot of things/layers and depths changing... If you could please send me how your layers are, I'll try to reproduce you problem with a fresh mock of what you have. I mean, try the same layer setup, room size and number of instances.

I do want to push it to the limit, at least to know the limit xD
If it doesn't give you more trouble than you already had with this, I'd appreciate if you could SS your layer arrangement and tell me the depths of those layers, so I can try to reproduce it =X

As soon as I have some time and build it up, I can also post the example here, with the problem and submit a bug report, or even give you a fresh and working mock, that may lead you to your old problem that someone else may also have :)

Thanks in advance bro
 

CodeManu

Member
Are you by any chance using the "depth = -y;" code in the Draw event? That used to cause problems in my game when ported from 1.4 to 2.0.
 

Ghiliam

Member
Hello again @Ghiliam

That's very good to know that all worked out!
To tell you the truth, I'm really interested in this case, since I have a new game planned that may have a lot of things/layers and depths changing... If you could please send me how your layers are, I'll try to reproduce you problem with a fresh mock of what you have. I mean, try the same layer setup, room size and number of instances.

I do want to push it to the limit, at least to know the limit xD
If it doesn't give you more trouble than you already had with this, I'd appreciate if you could SS your layer arrangement and tell me the depths of those layers, so I can try to reproduce it =X

As soon as I have some time and build it up, I can also post the example here, with the problem and submit a bug report, or even give you a fresh and working mock, that may lead you to your old problem that someone else may also have :)

Thanks in advance bro
Well no problem, I'll upload everything as soon as I can use some spare time (I'm at work right now :s). Only thing I'm sure to remember correctly is the layer's depth: 100 for the "ground" layers, 0 for the "upper" layers. All the other ones are pretty much randomic, since they only have invisible stuff.

Are you by any chance using the "depth = -y;" code in the Draw event? That used to cause problems in my game when ported from 1.4 to 2.0.
Nope, it was in step event. And I've never used 1.4, I began using GMS from this 2.0 version.
 

Shut

Member
Someone posted this code and it seems to solve that sprite appearing/disappearing issue.

depth = y;
depth = -depth;
 

Ghiliam

Member
Hello again @Ghiliam

That's very good to know that all worked out!
To tell you the truth, I'm really interested in this case, since I have a new game planned that may have a lot of things/layers and depths changing... If you could please send me how your layers are, I'll try to reproduce you problem with a fresh mock of what you have. I mean, try the same layer setup, room size and number of instances.

I do want to push it to the limit, at least to know the limit xD
If it doesn't give you more trouble than you already had with this, I'd appreciate if you could SS your layer arrangement and tell me the depths of those layers, so I can try to reproduce it =X

As soon as I have some time and build it up, I can also post the example here, with the problem and submit a bug report, or even give you a fresh and working mock, that may lead you to your old problem that someone else may also have :)

Thanks in advance bro
Hello MarceloP, here I have the layer folders, layers and their depths.

fld_graphics:
-text_layer [depth = -160]
-graphics_layer (textboxes, menus, ecc..) [depth = -150]
-gound_effects (ground-level animations) [depth = 100]
fld_player_super: (objects always above the player, circa 600/700 instances each layer) [depth = -100]
-player_super_1
-player_super_2
-planer_super_n
-...
fld_player: (object on the same level of the player, circa 800/1000 instances each layer) [depth = 0]
-player_1
-player_2
-player_n
-...
fld_system: (invisible objects for enviromental valorization)
-other_mediums (define the ground type: ground, water, deep water, rock walls, magma ecc..)
-system (sprites depth sorting mainly)
-jumper (define where the player can jump)
-tiles
-backgound

I hope you can find this useful :p



Someone posted this code and it seems to solve that sprite appearing/disappearing issue.

depth = y;
depth = -depth;
I'll try this out too!
 
Top