0 votes

Is there any way I can get the real size of a Control node on screen?

My stretch mode is 2d/expand. I've tried Node.get_global_rect().size and Control.size, but both of their results didn't change although I resized the window. The results are relative to the window size set in project configuration instead of their real size on screen.

I need the real size of a node on screen since my shaders depend on the screen resolution.

Godot version 3.3.4.stable
in Engine by (18 points)

1 Answer

+1 vote

Solved with the help of @nitricswight. One can just compare the current window size with the size in ProjectSettings to obtain the strech scale.

var screen_size = get_tree().get_root().size var set_width = ProjectSettings.get("display/window/size/width") var set_height = ProjectSettings.get("display/window/size/height") var real_size = size * screen_size / Vector2(set_width, set_height)

by (18 points)
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 Frequently asked questions and 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 [email protected] with your username.