Avoid letterbox in viewport keep mode

Godot Version



Hi everyone,

this code centers everything on any aspect ratio while showing overlapping background on bigger screens:

extends Node

onready var viewport = get_viewport()
onready var game_size = Vector2(

func _ready():
	viewport.connect("size_changed", self, "resize_viewport")

func resize_viewport():
	var new_size = OS.get_window_size()
	var scale_factor

	if new_size.x < game_size.x:
		scale_factor = game_size.x/new_size.x
		new_size = Vector2(new_size.x*scale_factor, new_size.y*scale_factor)
	if new_size.y < game_size.y:
		scale_factor = game_size.y/new_size.y
		new_size = Vector2(new_size.x*scale_factor, new_size.y*scale_factor)

	viewport.set_size_override(true, new_size)

Unfortunately different aspect ratios other than the project’s lead to some object-positioning issues. Such issues don’t appear when I use the “viewport/keep” display setting, but instead of my overlap-background letterboxes are shown.
Is there any way to script that “viewport/keep” mode while showing background instead of letterboxes?