Adjusting background to window size

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

Hi. I’m very new to Godot Engine, so sorry for this newbie question.

In my project, i have some interactive elements wich i need to always preserve its size, no matter the windows size. To achieve this, i disabled the Stretch mode in the project settings.

The problem is I also need the background image to stretch or shrink according to windows size. I’m using a TextureRect node for the background image. Due to my limited knowledge in godot, the only solution i have found is to adjust the TextureRect’s scale_rect property by code.

At first, i thoght i could simply adjust the background size automatically by making the TextureRec a child of some type of container (PanelContainer, HboxContainer, etc) and then tinker with their size flags, to get an ‘automatic’ background reescaling, but with this approach, the TextureRect doesn’t change its size when i change the size of the container.

Is there any method to reescale the TextureRect to window size other than doing it directly by code?

Thank you and sorry for my bad english. :slight_smile:

I’ll check those links. Thank you.

isdran | 2022-03-26 17:31

:bust_in_silhouette: Reply From: ponponyaya

Project Settings -> Display -> Window -> Stretch -> Mode = 2D.
Then all images will automatically scale follow the window size. If you want scale whole screen images, I think this is the simplest way.

But if you only want one specific image automatically scale when the window size changeed, use code to control will be better.

By the way, when you use code, you also can scale all the screen images by controlling the camera.

I’ll keep your tip about the camera in mind. Thank you very much!

isdran | 2022-03-26 17:30

In Godot 4.0 they renamed this option. It is called “canvas_items” now. At least I think/hope it was a simple renaming.

AgSmith95 | 2023-03-10 21:02