How to change the stretch (mode, aspect, shrink) by code?

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

I want to change the stretch in gd script by i can’t do

:bust_in_silhouette: Reply From: wombatstampede

Let’s assume that your 2D GUI has a size of 1280x720 then you could use the following to set the screen to half resolution (2x2 pixel on screen are 1x1 pixel of the game):

get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_VIEWPORT,  SceneTree.STRETCH_ASPECT_EXPAND, Vector2(1280,720),2)