+2 votes

Hi, this should be simple, but I can't figure it out. How do I get the dimensions of a sprite, and how do I set the dimensions of a sprite? In other engines, you would do something like sprite.getWidth(), but I have no idea in Godot. Thanks.

Godot version 3.2.1
in Engine by (591 points)

1 Answer

+6 votes

sprite.texture.get_width() and sprite.texture.get_height()
As far as I know, you can't resize sprite quickly. Instead you need to rescale it. If image has width of 100px, and you want to scale it to 150px, then you need to divide 150 by 100 and it will give you scale you need to set sprite.scale.x = 150.0 / 100.0 (note that you need at least one float in division to get float result (int/int=int, i.e. 150/100 = 1)).

by (1,554 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.