Problem while using function "get_size ( )".

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By momoko

Situation:
I have a node “sprite”
I’m trying to use function “get_size” 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 “get_size” isn’t declared in the current class.
But from what I seen here:Image — Godot Engine (3.0) documentation in English
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?

:bust_in_silhouette: Reply From: kidscancode

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: Texture — Godot Engine (stable) documentation in English , there’s a get_size() there too.

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

texture.get_size()