+2 votes

How to know the screen position of a node2D?

asked Aug 15, 2017 in Engine by cardoso (363 points)

2 Answers

+6 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).

answered Aug 15, 2017 by YeOldeDM (1,292 points)
selected Aug 15, 2017 by cardoso

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.

0 votes


answered Aug 15, 2017 by volzhs (9,320 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.