0 votes

If I have 2 overlapping sprites, how can I determine or detect which one is on top?

asked Apr 4, 2018 in Engine by sandheaver (99 points)

1 Answer

+3 votes
Best answer

Nodes are drawn in tree-order (except for special cases such as children of YSort nodes), so lower nodes are drawn on top. In GDScript you can test this using the is_greater_than() method:

if sprite1.is_greater_than(sprite2):
    # sprite1 is on top of sprite2
answered Apr 4, 2018 by eska (1,038 points)
selected Apr 4, 2018 by sandheaver

Thanks, that's exactly what I needed.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.