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

Legacy GM [SOLVED] always show object on top of other object which has relative depth

jobjorgos

Member
Hey

I want obj_boots always be shown on top of obj_peg (the player) in a 2d top-down (fake 3d perspective) game.

obj_boots
Step Event:
Code:
depth = (obj_peg.depth + -1);
But this doesnot work so I wanna make sure if anybody can confirm if this piece of code is right?

Greetz jobjorgos
 

The-any-Key

Member
obj_boots
Step Event:
Code:
// Find depth peg
var newDepth=0;
with obj_peg newDepth=min(newDepth,depth);
// Set depth
depth = newDepth-1;
If you have more that one obj_peg.

But your code should work. Make sure you dont set the depth in another place in the code.
 

jobjorgos

Member
Thanks for your reply.

I have just one single obj_peg so
Code:
depth = (obj_peg.depth + -1);
should be good, but indeed but for more obj_peg's then
Code:
// Find depth peg
var newDepth=0;
with obj_peg newDepth=min(newDepth,depth);
// Set depth
depth = newDepth-1;
would be a great solution.


Now with some tests I discovered the depth value of obj_boots is unchangable! :eek::eek::eek:

With debugging I saw the depthvalue doesnot go with 1 down. Even while I made a specify event 'Press U' that does -1 depth every time I press it doesnot change anything to the depth value whatever I do!
Very strange, only thing which changes the depth value is by moving up/down in the room which I also dont understand cuz this should only change the x and y position, not also depth I guess! How is this possible?
 
Last edited:

The-any-Key

Member
Very strange, only thing which changes the depth value is by moving up/down in the room which I also dont understand cuz this should only change the x and y position, not also depth I guess! How is this possible?
Search for "depth =" or "depth"

You change the depth somewhere in the code that you dont know about.
 

jobjorgos

Member
Thanks for the help, I did some research in meanwhile and I'm happy that I discovered this that fixed the problem:

obj_peg
Step Event:
Code:
depth = -bbox_bottom
obj_boots
Step Event:
Code:
depth = -y;
I still don't know whats the difference between 'depth = -1' and 'depth = -y', but that doesn't matter it works atleast.

I tried 101 things for obj_boots like
Code:
object_set_depth(obj_boots, obj_peg.depth-y);
Code:
depth = obj_peg.depth-1000
Code:
depth = obj_peg.depth-y*1000
Code:
depth = obj_peg.depth-y
etc etc but nothing worked untill I did

obj_peg
Step Event:
Code:
depth = -bbox_bottom
So this problem is solved now ;)
 
Top