How to get the real viewport size while using aspect : expand

Hi,

I’ve set a fixed resolution of 640x480, and then the aspect ratio to “expand”.
Now if I use :

	print(get_viewport().size.x)
	print(get_viewport().content_scale_size.x)

I get 1920 (so my actual resolution width) and 640.
The thing is, 640 is not the real width of the viewport, it’s something like the 850, because I have a 16/9 ratio, so the game kept the height of 480 and stretched the game, which is exactly what I want.

But how can I access my actual viewport width ?
I could simply calculate it using the user resolution ratio, but there MUST be a simple variable giving me this information, no ?

maybe get_viewport().get_visible_rect().size.x ?

my Tests:

image

func _process(delta: float) -> void:
	%Info.text = str(get_viewport().size.x) + " | " + \
	str(get_viewport().content_scale_size.x) + " | " + \
	str(get_viewport().get_visible_rect().size.x)
	pass

1 Like

Yes, we have a winner !

1 Like

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