|Attention||Topic was automatically imported from the old Question2Answer platform.|
I have a game that sets the window size and position based on saved data.
The code is executed in the
This method is good but it becomes annoying after a while because the game starts with the default window settings and adjusts the window when the game is ready.
What is the proper way of making the window start with the saved size and position (if it exists)?
I’m not looking for a way to adjust the window after running, I want the game to start with the saved position and size.
It’s not a huge problem but it would be great to have this behavior which is similar to almost every other program including Godot itself.
Here’s the code:
func _ready(): load_window_data() func save_window_data(): var new_data = window_data_class.new() new_data.window_maximized = OS.window_maximized if OS.window_maximized: OS.window_maximized = false new_data.window_position = OS.window_position new_data.window_size = OS.window_size OS.window_maximized = true else: new_data.window_position = OS.window_position new_data.window_size = OS.window_size ResourceSaver.save("user://user_data/window_data.tres", new_data) func load_window_data(): var dir = Directory.new() if not dir.file_exists("user://user_data/window_data.tres"): return false var window_data = load("user://user_data/window_data.tres") OS.window_position = window_data.window_position OS.window_size = window_data.window_size OS.window_maximized = window_data.window_maximized
I’m kind of a noob, but maybe it’s the _init() function or one of these others… that you want…
CassanovaWong | 2021-04-12 10:24
Tried these functions already with no success. I know that it’s normal but I’m looking for a way to make the game run with the window size already loaded and not adjust it after running.
Bubu | 2021-04-12 11:43
It is always good to add your code to a question. Guess my answer has overlap with your :-p
clemens.tolboom | 2021-04-13 09:51
Can you format your code a little … just add 4 space for each line
clemens.tolboom | 2021-04-13 12:03
Sorry, for some reason the formatting is lost when pasting, some underscores are missing as well.
Bubu | 2021-04-13 13:21