GMS 2 What is the good way to handle tile & object depth?

Discussion in 'Programming' started by RicardoVL, May 14, 2017.

  1. RicardoVL

    RicardoVL Member

    Joined:
    Jan 15, 2017
    Posts:
    19
    Hello all,

    I have some trouble in finding out what the correct way is of depth in GMS2
    The fences are tiles in 2 different layers, de upper half is above the NPC's layer
    and the bottom tiles beneath them.

    I want the characters to be able to walk to the fence and stand really close to it, just like in real life.
    I know there are some tricks to do with dept = -y but i only know this trick with objects
    I could make the fences into objects, but i think that's inefficient.

    And how to properly use depth between npc's, in the step event i do: depth = -y
    But when i do that the depth is overall and i can for example walk over trees. (i need to change that depth to??)

    [​IMG]
     
    Last edited: May 14, 2017
  2. RicardoVL

    RicardoVL Member

    Joined:
    Jan 15, 2017
    Posts:
    19
    BUMP

    Nobody knows this? ;o
     
  3. NicoDT

    NicoDT Member

    Joined:
    Jun 21, 2016
    Posts:
    237
    Hey! I'm not using GM2 yet, so the solution I have for GM1 may not work.
    What I do is having all the tiles I want to apply depth in a same depth level (in this case 900000), and in the room start event I change all those tiles to a -y depth.

    Code:
    var tiles
    
    var i
    tiles = tile_get_ids_at_depth(900000);
    
    for ( i =0 ; i< array_length_1d(tiles); i+=1)
    {
     if (tile_exists(tiles[i]))
     { tile_set_depth( tiles[i], -tile_get_y(tiles[i])-tile_get_height(tiles[i])+32)}
    }
    
    I don't know if those functions still work in GM2, or there is a work around, but since I will use GM2 for my next project I'd too like to know the solution for your problem.
     
  4. mar_cuz

    mar_cuz Member

    Joined:
    Dec 15, 2016
    Posts:
    211
    Hi Nicodt I'm interested in your way of doing this. What is the array_length_1d in your for loop? How would I set that and would this work for isometric tiles?

    Thanks
     
  5. NicoDT

    NicoDT Member

    Joined:
    Jun 21, 2016
    Posts:
    237
    Hi!
    What I do is store only the tiles at depth of 900000 in the variable "tiles" (these are the tiles I want to have a different depth depending on the Y coordinate.). What I do with array_length_1d is loop through all the tiles that were store in that variable, and then set a new depth.
    I have never done isometric tiles, so I wouldn't know for sure. Do your tiles have height? (like a Final Fantasy tactics map), if they don't have height then I guess you could use it the same way as I do. If they do have height, I'm not sure (maybe you can do it several times for different heights/depths? I have really no idea, sorry :confused:)
     
  6. mar_cuz

    mar_cuz Member

    Joined:
    Dec 15, 2016
    Posts:
    211
    I don't have height. Just flat ground. The attached image is my game atm. The walls are objects but I want to use the walls as tiles.
     

    Attached Files:

  7. NicoDT

    NicoDT Member

    Joined:
    Jun 21, 2016
    Posts:
    237
    Yeah, doing it the same way as I do should work just fine then.
    Just remember I do it for 1.4 , I have no idea if the same functions are available for GM2 or not.
    Let me know if you need any help when you do it.
     
  8. mar_cuz

    mar_cuz Member

    Joined:
    Dec 15, 2016
    Posts:
    211
    Thanks for that. Yes I'm on 1.4 as well. Well take your offer of help if I get stuck.

    Just quickly though, the array length 1d does not need to be pre set yeah? The for loop should still work without redefining the array elsewhere first?
     
  9. NicoDT

    NicoDT Member

    Joined:
    Jun 21, 2016
    Posts:
    237
    That's right, that's the only code needed.
     
  10. YanBG

    YanBG Member

    Joined:
    Jun 25, 2016
    Posts:
    561
  11. RicardoVL

    RicardoVL Member

    Joined:
    Jan 15, 2017
    Posts:
    19
    So you are saying that this solution is faster then tile_set_depth ? because you don't use loops?
    And do you use this method in gms2?
     
  12. NicoDT

    NicoDT Member

    Joined:
    Jun 21, 2016
    Posts:
    237
    This way doesn´t loop through all the tiles, only those that need the depth changed (so for example floor tiles won´t be considered).
    I never had a problem with it, but I have no more than 40 tiles that need its depth changed to value -Y , I´d recommend you to try placing many tiles to see if you have any problem.
     
  13. RicardoVL

    RicardoVL Member

    Joined:
    Jan 15, 2017
    Posts:
    19
    :'( this is an unknown function, its obslete in 2.0

    :'( this solution is only whe code created the tiles, but i do this in my room editor, ad perhaps it's obslete 2..
     
  14. NicoDT

    NicoDT Member

    Joined:
    Jun 21, 2016
    Posts:
    237
  15. BaBiA Game Studio

    BaBiA Game Studio Member

    Joined:
    Jun 20, 2016
    Posts:
    713
    I have addressed this in my game with a collision tile layer that stops the player at just the right point so that they don't overlap the "walk-behind" tile. So I would have the top half of the fence in the "walk-behind", the bottom half of the fence on the "ground" layer (which is below the player/instance layer in depth), and then a collision layer with my collision tiles running along the top edge of the bottom half of the fence. My movement/collision checking then blocks movement based on the player bounding box and the collision tiles top keep the player from overlapping either part of the fence.

    The downside is that it does keep the player away from smaller objects that you might want to be closer to.

    I could post some screenshots when I get home tonight if the above doesn't make much sense. :)
     
  16. RicardoVL

    RicardoVL Member

    Joined:
    Jan 15, 2017
    Posts:
    19
    Yes and i would like that the player can walk all the way to the fence just like in real life. It's not a majer issue but it would be way nicer, thats why i started this thread.
     
  17. RicardoVL

    RicardoVL Member

    Joined:
    Jan 15, 2017
    Posts:
    19
    Nothing good found yet. is it a "good" solution to make objects of things that have an advaced depth.
    I also want to make all trees objects so you can chop them.

    Aything against that, in speed or something?
     
  18. RicardoVL

    RicardoVL Member

    Joined:
    Jan 15, 2017
    Posts:
    19
  19. RichHopefulComposer

    RichHopefulComposer Member

    Joined:
    Jun 20, 2016
    Posts:
    1,357
    I just use objects for fences and stuff. You're not going to have a problem unless you have 5000 fences on the screen at once.
     
  20. JAG

    JAG Member

    Joined:
    Jul 5, 2017
    Posts:
    73
    @RicardoVL Hi have you found a solution to this yet? Im having the same issue!!
     
  21. kevins_office

    kevins_office Member

    Joined:
    Dec 19, 2017
    Posts:
    224
    Here it is 2018 and i have yet to find a solution for depth sorting tiles or sprites in GMS2. It seams like the depth sorting method only works on objects.
    Has anyone found a way for sprites drawn on an asset layer, or tiles in a tilemap, to be included in the depth sorting method?
    The method where you sort instances and control which has its draw_self() executed first to last without changing the depth variable.
     
  22. laekwondo

    laekwondo Member

    Joined:
    Mar 3, 2018
    Posts:
    1
    I used this tutorial for object depth, seems to work well:

    Edit: Here is an update to the Object Depth code, more efficient:
     
    Last edited: Mar 4, 2018
  23. JackTurbo

    JackTurbo Member

    Joined:
    Oct 19, 2016
    Posts:
    757
    You guys tried z-tilting? There's a great write up on it on the game maker tech blog, not tried it myself yet.
     

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