change viewport size by code

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

How could I change BY CODE the viewport size to fit different physical screen dimensions and aspect ratios?

:bust_in_silhouette: Reply From: Gluon

Well I havent implemented the code below but according to the documentation ( see here Using Viewports — Godot Engine (stable) documentation in English ) this should work,

Var Width_Set = 0
var Height_Set = 0

viewport.set_size_override(true, Vector2(Width_Set, Height_Set)) # Custom size for 2D.
viewport.set_size_override_stretch(true) # Enable stretch for custom size.

Tie the Width_Set and Height_Set variables into some user inputs and you should be able to set the size. If you check the website I directed too though it should give you more info.

Thanks but your suggestion didn’t work.

smaran | 2021-08-17 18:07