This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+4 votes

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 (76 points)

1 Answer

+7 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 (22,191 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?

If you use get_size() you can multiply that by the scale to get the current scaled size of the sprite

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.