• Godot Help
  • How can I change the main viewport size dynamically?

I am experimenting with creating a pixel-art mobile game in Godot. I am having trouble with the viewport size regarding the pixel art assets. I've learned that I should set the scaling mode to integer, which adds black bars to the screen. My plan to get rid of the black bars is as follows:

  1. Find a way to resize the main viewport dynamically in runtime
  2. Calculate, based on the device's size, what size the viewport should be
  3. Apply that calculation when appropriate

Before I even try to get a calculation like that going, I want to make sure I can change the viewport's size in the code, which I couldn't figure out myself. I have tried the following:

  • Changing the project settings in a _ready function: Does nothing
  • Changing the project settings in a _process function: Does nothing
  • Setting get_viewport().size in a _ready function: Does nothing
  • Setting get_viewport().size in a _process function: Changes the size of the viewport, but without expanding it
  • Setting get_window().size in a _ready function: Does nothing

What else can I try?

  • SnapCracklins replied to this.
  • Someone on the lemmy community helped me figure out the solution:

    get_window().content_scale_size = DisplayServer.window_get_size() / 3

    roydbt have you considered just changing the camera size? changing the camera is an easy way to change perspective on a 2d game without much work. or are you using a viewport for something in particular?

      SnapCracklins I am only using the viewport for displaying the game normally, nothing too complicated. How can I change the camera size directly? I haven't found anything about it in the documentation

      Someone on the lemmy community helped me figure out the solution:

      get_window().content_scale_size = DisplayServer.window_get_size() / 3