0 votes

I made a menu, it should pop up when the player presses Escape, but when the screen size is increased, the settings window becomes visible, which should not be, I was looking for solutions but nothing helped (

Game screenshot:
https://disk.yandex.ru/i/580pHFPxFnHjdA
(link for cloud drive)

code in autoload:

extends Node

 onready var vp = get_tree().get_root()
 onready var base_size = Vector2(1920, 1080)


  func _ready():
                # Use whichever you would like by default
            set_fullscreen()
            #set_windowed()


  func set_fullscreen():
      var window_size = OS.get_screen_size()

      if OS.get_name() == 'Windows' && window_size == base_size:
                        # Not sure if this works outside of Windows / native resolution.
                        #  - Mac didn't like it, nor smaller resolutions.
          OS.set_window_fullscreen(true)

      else:
          var scale = min(window_size.x / base_size.x, window_size.y / base_size.y)
          var scaled_size = (base_size * scale).round()

          var margins = Vector2(window_size.x - scaled_size.x, window_size.y - scaled_size.y)
          var screen_rect = Rect2((margins / 2).round(), scaled_size)

          OS.set_borderless_window(true)
          OS.set_window_position(OS.get_screen_position())
          OS.set_window_size(Vector2(window_size.x, window_size.y + 1)) # Black magic?
          vp.set_size(scaled_size) # Not sure this is strictly necessary
          vp.set_attach_to_screen_rect(screen_rect)


  func set_windowed():
      var window_size = OS.get_screen_size()
          # I set the windowed version to an arbitrary 80% of screen size here
      var scale = min(window_size.x / base_size.x, window_size.y / base_size.y) * 0.8
      var scaled_size = (base_size * scale).round()

      var window_x = (window_size.x / 2) - (scaled_size.x / 2)
      var window_y = (window_size.y / 2) - (scaled_size.y / 2)
      OS.set_borderless_window(false)
      OS.set_window_fullscreen(false)
      OS.set_window_position(Vector2(window_x, window_y))
      OS.set_window_size(scaled_size)
      vp.set_size(scaled_size)

help pls

Godot version 3.3
in Engine by (15 points)

1 Answer

0 votes

It is unclear what is exactly your problem. To handle multiple game resolutions I suggest to you to read following pages:

https://docs.godotengine.org/en/stable/tutorials/gui/size_and_anchors.html
https://docs.godotengine.org/en/stable/tutorials/viewports/multiple_resolutions.html

If you want to simply show/hide menu, then you can use visible property of Control nodes to quickly show/hide controls.

by (1,650 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.