Scaling the viewport for multiple devices

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

Godot Version: 3.1 BETA 1

Hi folks,

I’m having trouble scaling the viewport for different devices. Initially I was using the “2D” stretch mode… but this gets a bit wonky with aspect ratios that are different from the artwork. I’ve gone for a pixel art style so clean scaling is important.

I have my stretch mode set to “viewport” and aspect set to “ignore”. Here is what I have tried…

viewport.set_size_override(true, new_size_v2, Vector2.ZERO)

The above seems to be ignored. The image is fullscreen and stretched.

viewport.size = new_size_v2

This didn’t help, the artwork was still small in the top left corner.

viewport.set_attach_to_screen_rect(Rect2(position_v2, size_v2))

This does set the position and size correctly, but leaves the Godot splash screen in the background flickering.

Has anyone tackled this problem? If so, how did you get around it? Ultimately what I am looking to do is scale the viewport so that the game fits within the screen. Then, on devices with different aspect ratios, perhaps use a second viewport to render a background image to fill in the black bars.

Any input or pointers would be super helpful. Thanks :slight_smile: