Here is my code I use to switch between portrait and landscape on mobile. You should be able to edit it to change to whatever aspect you want to force (or use the current resolution to scale dynamically to the full screen size):
extends AspectRatioContainer
onready var root_node = get_tree().root
const aspect_16_by_9 = 16.0 / 9.0
const aspect_9_by_16 = 9.0 / 16.0
func _ready():
root_node.connect("size_changed", self, "adjust_aspect")
adjust_aspect()
func adjust_aspect():
var current_aspect = get_aspect_ratio()
if current_aspect > aspect_16_by_9:
ratio = aspect_16_by_9
elif current_aspect < aspect_9_by_16:
ratio = aspect_9_by_16
else:
ratio = current_aspect
func get_aspect_ratio():
var resolution = get_viewport_rect().size
return resolution.aspect()