Displaying sprites with dependence on player's position

Shirted-VanesShirted-Vanes Posts: 4Member

I've got a scene with player and some objects. For now my player (his sprite) is displayed that he's behind objects. If player is closer than object, he's sprite is still behind (of course). I've noticed that it's regulated by hierarchy of objects in "Scene".

Now how can I change hierarchy of my player through scripting with dependence on his Y-position? For some reason I can't find info about this; neither in Google nor in Godot Documentation.
Thanks in advance.

Tagged:

Tags :

Answers

  • TwistedTwiglegTwistedTwigleg Posts: 1,049Admin
    Answer ✓

    I have not used it myself, but I think the YSort node will sort 2D nodes based on their Y position. I think the YSort node only sorts the children nodes under it though, so you may need to restructure your scene tree a bit to use it.

    Hopefully this helps! :smile:

  • Shirted-VanesShirted-Vanes Posts: 4Member

    @TwistedTwigleg said:
    I have not used it myself, but I think the YSort node will sort 2D nodes based on their Y position. I think the YSort node only sorts the children nodes under it though, so you may need to restructure your scene tree a bit to use it.

    Hopefully this helps! :smile:

    "...The child node must inherit from CanvasItem for it to be sorted..."
    Um... I see it's for GUI, for Canvas. I'll try this but I ain't sure it can help. :/
    Thanks anyway.

  • CalinouCalinou Posts: 217Admin Godot Developer
    edited January 24 Answer ✓

    @Shirted-Vanes said:
    "...The child node must inherit from CanvasItem for it to be sorted..."
    Um... I see it's for GUI, for Canvas. I'll try this but I ain't sure it can help. :/
    Thanks anyway.

    Both Control and Node2D inherit from CanvasItem, which means it works with basically any 2D node, GUI or not.

  • Shirted-VanesShirted-Vanes Posts: 4Member

    Hm. Okay, it works. Thank you, @Calinou & @TwistedTwigleg.
    Now I have another problem: there is sorting by centers of objects and it looks bad. :D
    But this is other question, topic is closed.

  • Shirted-VanesShirted-Vanes Posts: 4Member

    Yay, no problems. I've been seeing for sprite's offsets and have set them correctly.
    Topic is closed 100%!

Sign In or Register to comment.