How to execute GDScript befdore the game window is shown to the user?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By user41420082
:warning: Old Version Published before Godot 3 was released.

I have a script for centering the game window and I put it on the _ready() function. However, it doesn’t fire fast enough and as an end result, the game window opens at the top left of the screen and pops to the center. Is there a way to make it start at the center immediately?

var screen_size = OS.get_screen_size()
var window_size = OS.get_window_size()
OS.set_window_position(screen_size*0.5 - window_size*0.5)

This is my code for centering the window.

:bust_in_silhouette: Reply From: Nophlock

Hi,

you can center the game window from the “Editor Setting” which are available under the “Settings” button in the editor. From where you have the option “Game Window Placement” where you can define where the game window should appear(“Rect” option). Hope that helps you :slight_smile:

Hi, this doesn’t work. it does the same thing as my script. The game window pops up at the top left for a brief moment and then pops back to the center. I want the game to open in the center immediately.

Not to mention, doesn’t work on my compiled game whereas my script does.

user41420082 | 2016-07-23 13:35

Okay sorry I actually only tested this with the godot 2.1 beta and not with the 2.04. Seems they changed that with version 2.1 because in this version it’s immediatly in the center. But in that version it also doesn’t affect an exported game like your already mentiond(at least for me), so I’m also clueless at the moment, sorry :confused:

Nophlock | 2016-07-23 14:37

No worries! Thanks for trying to help!

user41420082 | 2016-07-23 16:18

:bust_in_silhouette: Reply From: Zylann

See this issue Open Godot's windows at a better position · Issue #5626 · godotengine/godot · GitHub

Thanks! It seems it’s coming in 2.1, I guess I’ll just wait for the stable to come.

user41420082 | 2016-07-23 16:18