GMS 2 how to control the object foreground

Discussion in 'Programming' started by Dwighty4000, Oct 12, 2019 at 8:40 AM.

  1. Dwighty4000

    Dwighty4000 Member

    Joined:
    Sep 25, 2019
    Posts:
    8

    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
     
  2. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,959
    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).
     
  3. Dwighty4000

    Dwighty4000 Member

    Joined:
    Sep 25, 2019
    Posts:
    8
    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?
     
  4. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,703
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice