Is it possible to retain the aspect ratio when resizing a window?

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

I want the player to be able to resize the window, but I want it to keep the aspect ratio of the window when resizing.

Edit: For clarification, I don’t want just the game to retain it’s aspect ratio, instead I want for the entire window to keep it’s aspect ratio while resizing.

:bust_in_silhouette: Reply From: exuin

Here is my kinda glitchy solution:

extends Node

const RATIO = 600.0 / 1024.0

func _ready():
	get_tree().get_root().connect("size_changed", self, "set_window_aspect_ratio")

func set_window_aspect_ratio():
	OS.window_size = Vector2(OS.window_size.x, OS.window_size.x * RATIO)

If you find a better solution please let me know!

This is the solution I found

JorensM | 2021-09-13 17:23

Thanks, do the job !
Don’t forget the .0 → crash on macOs if not
Have a nice day !

PEIGNAULT Laurent | 2022-09-20 09:31