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.
0 votes

i have a scene with a texture rect (whose texture is loaded time to time from pictures in a folder) and an "Expand" button.
I want it to have a pretty simple beahaviour:
1. if the picture dimension is bigger than the screen, i want it to scale it down to fit the screen
2. if the picture dimension is smaller and expand is pressed, i want the texture to be scaled up to fill the screen dimension
3. If the picture dimension is smaller and not expanded, the texture remain had the same dimension of the screen
4.I want the picture to always remain in the middle of the screen and to keep its aspect ratio.

Is there a way to do it with control nodes? ideally, the perfect code would control the expand and stretch_mode of the texture rect properties only.
I really cannot find a way to make it work easily

in Engine by (1,514 points)
edited by

1 Answer

+1 vote
Best answer

right now, my best solution is to manually set position and dimension:

var maxs=max($TextureRect.texture.get_size().x, $TextureRect.texture.get_size().y)
    if maxs>screen_size.x or maxs>screen_size.y:
        if expanded:
by (1,514 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.