GameMaker how to control the object foreground

D

Dwighty4000

Guest

How can I change the foreground priority of objects during the game with programming commands so that this optical error on the characters (see picture on the bottom) can be avoided?

It should somehow be possible to distribute the foreground priority with codelines, so that in this case the girl would have the maximum foreground priority so that this optical error does not arise like now on the picture...

Runner 2019-10-12 09-20-24-019.jpg
 

NightFrost

Member
This is an issue of depth. The simplest solution, which still works in GMS2, is to set each instance's depth by
Code:
depth = -y;
after they have moved. Depth, simply put, is distance from camera, which dictates draw order, and this code puts it into negatives, or very close to the camera.

In GMS2 this actually creates temporary layers ("managed layers") at given depth for these instances. The practise is not recommended because it creates extra work with the temp layers, you're sidestepping advantages of layers, and you cannot manipulate these layers through code... but it works. Note that depth is not just an issue with "foreground" (which has no definition in GMS) but everything that gets drawns has a depth taken from their associated layer. This includes the background image(s).
 
D

Dwighty4000

Guest
This is an issue of depth. The simplest solution, which still works in GMS2, is to set each instance's depth by
Code:
depth = -y;
after they have moved. Depth, simply put, is distance from camera, which dictates draw order, and this code puts it into negatives, or very close to the camera.

In GMS2 this actually creates temporary layers ("managed layers") at given depth for these instances. The practise is not recommended because it creates extra work with the temp layers, you're sidestepping advantages of layers, and you cannot manipulate these layers through code... but it works. Note that depth is not just an issue with "foreground" (which has no definition in GMS) but everything that gets drawns has a depth taken from their associated layer. This includes the background image(s).
I would like to implement that so that the girl is drawn over the player as soon as the player coordinate of the height is greater than that of the girl. The same then again the other way around when the player is deeper than their coordinate, the player should be drawn for foreground.
But how can I make that the player and the girl do not bend under the floor of the wood texture because this is also an object with a sprite to?
 

Yal

šŸ§ *penguin noises*
GMC Elder
The background's depth needs to be the highest (largest positive number) of all the things in the scene. But just setting it to 0 is enough, since the depth = -y trick will make sure all objects have negative number sizes, and zero is larger than a negative number.
 
Top