|Topic was automatically imported from the old Question2Answer platform.
When setting a texture to a sprite the size of the sprite changes according to the texture, why is this and can I disable this behaviour?
To further clarify the issue I’m having with an example: assume I have a sprite of size 20x30 (transform.scale) with a 1x1 texture. Then I want to use a different texture for the sprite so I decide to use a texture of dimensions 10x15 then all of the sudden the dimensions of the sprite are now (10*20x15*30) but I want the sprite to remain fixed at 20x30 regardless of the size of the given texture.
This is how Godot works. Units of the 2D engine are in pixels, and there are no further size conversions. So when you set a texture on a sprite, the sprite takes the same size as the texture.
If you want to undo that behavior, you can have a script modify the scale using a reference size:
scale = Vector2(20, 30) / texture.get_size()
Or you could even make a custom node in which you use
_draw() to render textures at a fixed size no mattter what they are.
If you are making a GUI, you could also use the
TextureRect node instead (it’s a Control node so you can give it a size even without a texture), then make the
expand property checked and
stretch mode set to