Search Unity

Drawing order for 2D game

Discussion in '2D' started by Waliactico, May 20, 2016.

  1. Waliactico

    Waliactico

    Joined:
    Jan 16, 2013
    Posts:
    91
    I'm developing a 2D game, tile based with a cenital view (somewhat like bomberman).
    I've a problem with drawing order for walls and characters. Picture a wall that has a collider 1 tile thick, but the tile above it has some "decoration" to make it look "less cenital", like the top part of the wall. Something like this:

    montaje.png

    The tile 1 has physics, the tile 2 is just decoration. Tile 2 must be on a drawing order higher than the player, to cover its feet if he is above the all.
    BUT, there is not a good drawing order for the tile 1 that makes it look ok. I've tried:

    A) Drawing the wall on a higher drawing order than the character: With this approach, if a character is below it and its sprite is taller than 1 tile, then the wall will cover it partially, looking unreal.

    wrong_a.png

    B) Drawing the wall on a lower drawing order than the character: With this approach, if a character is above it, and some animation has a sprite that goes below its feet, then it will be visible below the tile 2.

    wrong_b.png

    So... how can I make this look ok??

    Thank you very much for your time!
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    You could set the sorting order based on the player's Y value.

    If the player's Y value is greater than the sprite's, set the sprite to a higher sorting order. If the player's Y value is less than the sprite's, set the sprite to a lower sorting order.
     
  3. Waliactico

    Waliactico

    Joined:
    Jan 16, 2013
    Posts:
    91
    I was thinking something like that, yes, but I was hoping that some other workaround was possible...
    Well, I think I'll be going for that. Thanks for your answer!
     
    LiterallyJeff likes this.