+1 vote

Hi.

I'm new to Godot.
I would like to get the width and height of a node in pixels using code but I can't find a way to get this property. I was searching the forum, the docs and the web and seems like everyone mentioning how to get scale but I don't need the scale (1:1) value.

I need the actual width and height in pixels of a Sprite or a Node2D node but I can't figure out how to get it.

I would appreciate any help.

Thanks.

in Engine by (59 points)

1 Answer

+3 votes
Best answer

A Node2D does not have a size, it only represents a position/rotation/scale (ie transform), and does not have any visual representation.

To get the size of a Sprite, you look at its texture property:

var size = texture.get_size()
by (19,651 points)
selected by

Thanks a lot. It worked :)

if it worked, would you select the answer please? so others looking for the same answer can reach the solution easily!:)

It returns the actual size of the image, but not the size at which it is displayed in case it's scaled. How could we get that information also?

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.