Help about the viewport

Godot Version

4.3

Question

Hi, i’m new to this so, here is my question, im going direct.

I have a pixel art proyect that has a 320x224px viewport, now i want to have it borders like, the gameplay is in the center and around it the border, then, there i tried to modify the proyect settings viewport to 1536x864 (16:9) then make a scene with the gameplay in a subviewport in the middle and scale it, after many tries it just or gets out of the displaying screen or the actual viewport is a little smaller when i play.

Here is some screenshots about it, sorry if my english is bad or dont understand some things.

I don’t see any screen shots. A screens hot of the scene tree would be the most helpful.

I see, they didnt upload because my device have a bug or smth, so there is 2 links to the screenshots:

In addition, in proyect settings i have keep aspect and display viewport thing

Do you have stretch to fit enabled in your SubViewportContainer? Try to enable that.

1 Like

Well now in the subviewport container scale is now activated, thing i did not activated then but now i do, so also i did make the root a canvas layer to see if changes something.
But it just looks the same

Here is some captures after i tried doing that:

Im starting to believe its a engine bug or smth bc in the editor it looks totally fine but in gameplay is well, another thing idk

Hey a update for this thing, i was playing with the viewport for at least 30 minutes i figured out that with 1280x720 works fine but, if i manage to make it bigger than that the gameplay looks bigger like scaled, here is two examples:
The first capture is 1536x864px
And second is 1920x1080px

Idk if it helps…

If you want your SubViewport to scale, you’ve got to listen to the window resize event and scale it yourself. What you are seeing is the SubViewportContainer sizing (the black bars). Add this script to your SubViewport, and update the border_width variable to the correct size.

## Border width in pixels
@export var border_width: int = 20


func _ready() -> void:
	get_viewport().size_changed.connect(_on_window_size_changed)


func _on_window_size_changed() -> void:
	size = get_window().get_size() - Vector2i(border_width * 2, border_width * 2)