0 votes

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

in Engine by (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
by (1,086 points)
selected by

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.