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?

  • plofi
    link
    fedilink
    21 day ago

    @roydbt You can change the window size if you need to by using get_window.size, but you should also use the Window.content_scale_size for further adjusments

    • @roydbtOP
      link
      11 day ago

      And where should I put that? In a _reaay or a _process?

      • plofi
        link
        fedilink
        210 hours ago

        @roydbt I assume you want to do scaling once at start so ready would be the best choice since process is called many times every second

        • @roydbtOP
          link
          23 hours ago

          Thanks, setting get_window().content_scale_size = DisplayServer.window_get_size() / 3 works! Now I only have to figure out what 3 stands for

  • BougieBirdie
    link
    fedilink
    English
    7
    edit-2
    2 days ago

    I haven’t developed for mobile, but I have played around with pixel art in games. Here’s a guide which probably outlines the why of it better than I can.

    It sounds like to git rid of the black bars, you want to open ProjectSettings/Display/Window/Stretch and set Mode to Viewport and Aspect to Expand.

    • @roydbtOP
      link
      22 days ago

      I did set the aspect to expand, but when I set the scaling mode to integer instead of fractional it adds the black bars