Make a viewport stretch.

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

I need to make game with normal GUI that’s fullscreen. But when the button is pressed, need to switch to a scene with a viewport(?) that’s only 160x100 pixels. And it need to be fullscreen. As if you make a game 160x100 resolution and set stretch mode to 2d and aspect to keep. But it only needs to be that way at one scene. Because when I tried making the hole game that size, GUI get’s all funked up. So I think I need to make a viewport or something, that’s 160x100 and draw everything onto it, and then make it occupy all screen.
Thanks in advance

:bust_in_silhouette: Reply From: MisterMano

You can do that with the function get_tree().set_screen_stretch(). That function takes the following arguments, which can all be referenced through SceneTree constants:

StretchMode (2D, Viewport, Disabled)
Aspect (Ignore, Keep, Expand)
MinSize (Vector2(x,y))

So, what you’ll want to actually change is that 3rd argument. A simple call like this on the scene’s _ready() will show you whether it’s working or not:

func _ready():

If you also want to force the screen into fullscreen, you’ll have to set a OS parameter: OS.window_fullscreen = true

Thanks, a life saver!

EnrikeChurin | 2021-08-25 21:50

1 Like
:bust_in_silhouette: Reply From: bath_idea

You can set it up on design time in editor. Depend on your target is landscape or portrait.
I’d like to share some important setup for mobile to support wider screen.

  1. If you use viewport don’t forget to set ViewportContainer->Stretch property to “ON”
  2. Camera3D->Keep Aspect to Keep Height for landscape or Keep Width for portrait.
  3. Project Settings->Display->Window->Stretch->Mode to 2D
  4. Project Settings->Display->Window->Stretch->Aspect to expand
    enter link description here