• 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 Depth problem: Position update

Dupletor

Member
I have an object behind a window, and I want it to move with the window.
As it is behind the window, it has a lower depth, which means it will be drawn before the window.
By the time its draw event happens, its position in relation to the window can't be updated. This is made in the window draw event.
As a result, the lower depth objects have their position updated after they are drawn, and they result on a flickering effect.

To solve this problem, I made the lower depth objects Draw event do nothing, and apply the drawing in the higher depth drawing event, and force the higher depth to be drawn after.

Code:
with(lower_depth_object) {
      x -= other.diffx;
      y -= other.diffy;
      draw_self();
}
draw_self();
This way I successfully simulated the existence of lower depth while keeping the next step update, removing the flickering.
However, this feels like it makes depth itself useless, I could simply make a huge drawing event that draws every object on the convenient order.

What would be the proper way of reordering the Draw events so their position can be updated before they are drawn and they keep a lower depth than the window?
 

TheouAegis

Member
So where are you updating the position of the window? Why do you need to use the draw event, apparently, to update the position of the window and whatever object is behind it? You do realize there are other events that occur between the step event and the draw event, right?
 

bbbower

Member
I would suggest using the end step event, or cycle with the begin / step / end events rather than moving the x/y in the draw event. If you do anything besides draw in the draw event you will end up with some weird issues so I would not change x/y in a draw event. You can also simply set the depth of the item which will coordinate its drawing sequence in pipeline. You can also just put a blank comment in all those objects draw events and make them have a parent object (aka parent:top_level parent:bottom_level) and have an object controller in the room do the with (parent) { draw_self();} in the order you want.

Here's a good explanation
 

Dupletor

Member
So where are you updating the position of the window? Why do you need to use the draw event, apparently, to update the position of the window and whatever object is behind it? You do realize there are other events that occur between the step event and the draw event, right?
From past experiences, updating position in the step event of a position inheritance child causes flickering. The way I found to solve it was by updating its position on the higher depth object drawing event, instead of in its own step event. But this technique only seems to work if the inherited position has a lower depth, which forces the update to happen before the draw event.
 

Dupletor

Member
You can also just put a blank comment in all those objects draw events and make them have a parent object (aka parent:top_level parent:bottom_level) and have an object controller in the room do the with (parent) { draw_self();} in the order you want.
I think I did exactly that, without inheritance or a separated control object. Either way, this control system seems to destroy the purpose of depth.
I will take a look on the end step event, but might probably have the issues I had with the Step event.
 

bbbower

Member
I think I did exactly that, without inheritance or a separated control object. Either way, this control system seems to destroy the purpose of depth.
I will take a look on the end step event, but might probably have the issues I had with the Step event.
Yes it does kinda kill the depth, however layers were supposed to be a better solution for GMS2. I still however end up making my own draw pipeline anyway for complicated projects. Gives me more control than the default system that many times acts unexpectedly or requires more tweaking work to be done than to just come up with a system to draw it yourself lol.
 
Top