0 votes

Hello Everyone,

So probably a fairly simple question and I've spent a lot longer trying to figure it out then I want to admit.

I'm attempting to setup a basic options page with some screen modes and screen resolution selections. The issue is... no matter how I pass those selections I cannot for the life of me get it to actual change the game screen.

I've attempted several methods:

My method thus far is that I have an options page with two drop down list - one for resolution and one for green mode.

When you select something in the drop down I call the itemselected(index) func and I simply match that to the index. So 1: for 1920 x 1080. Then based on that match I perform the process of adjusting the necessary variables -- the issue is no matter what I change -- the resolution doesn't change.

I've attempted to adjust the width/height of the display under the "display/window/size/width" and "display/window/size/height" paths From what I can discern this seems to be the correct way to set the resolution -- but adjusting these in-code has not done anything for me using:

ProjectSettings.set_setting("display/window/size/width", "Example")

I've attempted to adjust the "rect" of the root node of the tree.

I've attempted to adjust the view port size.

Code wise this is where I have ended up:

extends OptionButton

var x = 1024
var y = 600

var ScreenRes = Vector2(x, y)

var SelectedRes = null

func _on_ResolutionOptions_item_selected(index):
    SelectedRes = index
    match SelectedRes: #1024 x 600
            x = 1024
            y = 600
        1: #1920 x 1080
            x = 1920
            y = 1080

Help would be much appreciated.

in Engine by (12 points)

1 Answer

+1 vote

You have to use get_tree().set_screen_stretch(). You can check out this tutorial: https://gdquest.com/tutorial/godot/2d/settings-demo/

Basically, you have the same options that you have in settings, as parameters to that function, for example:

get_tree().set_screen_stretch( SceneTree.STRETCH_MODE_2D, SceneTree.STRETCH_ASPECT_KEEP, settings.resolution)
by (3,491 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.