+7 votes

How to know the screen position of a node2D?

in Engine by (373 points)

2 Answers

+12 votes
Best answer

get_global_transform_with_canvas() will return a node's transform relative to your viewport. The o property of this will be that transform's origin (position if you will).

by (1,326 points)
selected by

As of 3.1.1, o had been renamed to origin so get_global_transform_with_canvas().origin

Perhaps i'm mistaken, but in my tests, getglobaltransformwithcanvas().origin is giving me the global position, not relative to the viewport... how can i get that position? I need to use it on a shader.

It returns the position to the top-left corner of the window for me in the 2D Platformer demo. You probably wanna open a new question for this.

–3 votes

node.get_global_pos()

by (9,664 points)

But doesn't the node.get_global_pos() gives the position on the "world"?

If a camera is centered on a node, the node will always be centered on the screen (same screen position always), but the node global pos will be changed as the node is moved.

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.