How to Dynamic Resize of Images in a Menu?

Godot Version

4

Question

I am new to Godot, so this may be an elementary question. I am trying to use an image menu, the menu is as such:

image(TextureRect)
button1
button2
button3

I have put all of this inside a Vbox. I have found a way to dynamically change the text size in the buttons based on screen size - but I cannot identify a method to change the image size.

The image is contained inside a TextureRect. I have been reading some advice, so I have added a minimum size to the textureRect. So when I run the game the textureRect is now displayed at that minimum size.

How can I scale the textureRect dynamically? I haven’t found any code I can apply, for example:

%TextureRectName.changeTheSizeTo.x = 100
%TextureRectName.scaleTheRectTo.x = 1 * .5

No matter what I do the image (TextureRect) stays the same minimum size. People keep saying to have it ‘fill’ - but If I alter the container sizing it just stretches the image, and it is not proportional.

Any advice? I don’t want to resort to having a number of different image sizes and swapping them based on the device size, that seems like an antiquated approach. Any advice would be helpful!

Welcome to Godot!
I recommend you still use TextureRects, I haven’t used it in containers yet, but in Godot, usually objects inside containers can be resized dynamically.
In this case, you can use custom_minimum_size to change its size.
Your description is a bit complicated and vague, so I can’t offer more help at this time, I recommend using TextureRects and asking accordingly

I updated the question with a simpler example. Thanks.

It probably works:

%TextureRectName.custom_minimum_size.x *= 1.5 #custom scale
%TextureRectName.custom_minimum_size.y *= 1.5 #custom scale
1 Like

YES!!! Thanks so much! I was soooo close but I had not tried that. PERFECT solution, so simple! Thanks again for your help!!!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.