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.
+1 vote

I have a node "sprite"
I'm trying to use function "getsize" to get the size of an image attached to the node
Now I'm not sure how to make it work.
I tried "size = get
size ( ) "
and it shows: Parser Error: The method "getsize" isn't declared in the current class.
But from what I seen here:
It seems get
size is a built-in function, which means I don't need to manually define it.

Can anybody give me some suggestions to solve this problem or learn to avoid such problems?

Godot version latest
in Engine by (16 points)

1 Answer

+2 votes
Best answer

You said your script is on a Sprite, but the get_size() function you linked is on class Image. That's why you get the message that it's not declared in the Sprite class.

The image that the Sprite node is displaying is in its texture property. Its type is Texture. As you can see from the Texture doc: , there's a get_size() there too.

So, to get the sprite's size, you would use

by (22,191 points)
selected by
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.