#window_center needs 10 frame delay?

1 messages · Page 1 of 1 (latest)

true blaze
#

Today I discovered by experimentation that window_center() needs to be called 10 frames or more after switching from fullscreen to windowed mode. This seems to only be the case if the game starts in fullscreen mode. Documentation just says "at least one frame". 10 frames causes noticeable flicker when toggling modes...

I suspect something else is going on in my code, but I don't see any other delay that could be introduced (everything my code does happens on the first frame of loading the game). Maybe something funny happens only when loading the game, as it toggles to fullscreen mode?

The thing that bothers me about this is I fear I cannot guarantee this 10 frame delay will be the same on other machines. (1) I'd like to know WHY this is happening because it irritates me. (2) I'd like to know how to detect when window_center() actually worked, so I can call it every frame until it does work. (window_get_x/y might work here).

fresh river
#

this keeps going back and forth

#

it works instantly for me these days

true blaze
#

Huh... I am on .04 atm. I could test on .06 temporarily to see if it's better.

#

Any idea why this happens, or how to detect it so I can guarantee it works instead of just adding an arbitrary delay?

fresh river
#

2023.4?

true blaze
#

Sorry yes, that's what I meant.

#

I add the zeroes by sheer instinct.

fresh river
#

i remember it was like, you needed an event delay for years. like alarms pop off between begin step and step so we were doin alarm[0] = 1 and then putting window_center in the alarm, like that worked. then out of nowhere the delay was gone, window_center was working instantly. then there was a version (probably .4) where it stopped quite working, and is now afaik back to being instant

#

like this real quick setup works instantly for me in 2023.6

true blaze
#

Huh... Okay I will test in .6 and also check changelogs, maybe it's mentioned.

#

Thanks.

fresh river
#

afaik its never been mentioned in the changelogs

true blaze
#

Any major issues in .6 I should watch for, or am I good to upgrade?

fresh river
#

i've had no issues

true blaze
#

👍 Thanks fellows.

#

I will try it now.

fresh river
#

do your back ups and your what notz

true blaze
#

yes yes, I did a safety commit

#

i'm releasing a build today so I normally avoid updates until after, but I'll try this and worst case scenario I'll roll back and push this bug to the next release

#

Hm... not fixed on .6

#

Something else is going on then.

fresh river
#

are you window centering out of full screen?

true blaze
#

I am switching out of full screen, then centering the window.

#

it could be something like the game is still in fullscreen for 10 frames after switching, but that is what I assumed the 1 frame mentioned in the documentation was meant to account for

#

if the game launches in windowed mode it works correctly

fresh river
#

hmm, so centering the window doesnt work right out of fullscreen for me

#

but if i recall it should put the window back where it was before you fullscreened it anyways which it doesnt seem to either, (not sure if thats the behavior i remember) so entirely possible this is a bug

#

haha you know what does work?

true blaze
#

does it work for you if you delay by 10 frames?

#

oh, what?

fresh river
#
//no worky
if (keyboard_check_pressed(vk_tab) == true) {
    window_set_fullscreen(!window_get_fullscreen());
    window_center();
}
//yes worky
if (keyboard_check_pressed(vk_tab) == true) {
    window_set_fullscreen(!window_get_fullscreen());
    window_set_size(1024, 1024);
    window_center();
}```
true blaze
#

ohhh hmmmmmm

fresh river
#

using window set size to resize it to its windowed size and centering it does work, which is hilarious to me

#

lemme play with that cause i suspect thats not gunna work forever

true blaze
#

that's already what I'm doing, actually...

fresh river
#

okay so yeah this is fucking weird

true blaze
#

uhhhh I just got a different behavior and haven't changed anything

#

now it's in the top left corner, instead of the bottom right corner

#

(still not centered)

fresh river
#

okay so i think i have figured this out

#

if you go to fullscreen and use window_set_size to make it the same size it was before fullscreen then it remembers where its supposed to be

#

which is what it should do, thats a user expectation: move the window to the left, fullscreen, unfullscreen, window should be back in the left

true blaze
#

okay so my issue is that the default position for when it is set to a new size is inane

#

except if I call it 10 or more frames later it finds a sensible location

fresh river
#

if you resize it to anything else, it puts it in a wherever (top left corner for me). if you do not resize the window (which you shouldnt have to) after fullscreening, it seems to nearly center it

true blaze
#

top left corner would almost be acceptable

#

THIS is where it puts it for me

#

the top left corner is in the center

#

wait.......

#

waiit

#

that is centered correctly if the camera is 0 x 0

#

which is what I instantiate it to before resizing it

fresh river
#

oh that function

#

i hate that function heh

true blaze
#

how should I do it instead?

#

I'm testing some variations

#

actually I guess I just create it only once I find the new size

#

instead of creating a blank one at the start

fresh river
#

you should just make it once and leave it heh

#

and not create anything new

#

the way that camera follows objects suckssssss so hard

true blaze
#

yeah I don't use camera following, I do that myself

fresh river
#

cool yeah then you should just skip that heh

#

pop something like this in your room start eventgml view_enabled = true; view_visible[0] = true; camera_set_view_size(view_camera[0], width, height) camera_set_view_pos(view_camera[0], 0, 0);and then in your end step event focus it

#

make sure you are keeping everything in ratio. this is not something you should be touching when switching window sizes or modes though. the only time the view size usually needs to change is if you wanna zoom in and out

true blaze
#

ummm

#

well that might be an issue

#

because my code choses an aspect ratio to maximize screenspace depending on fullscreen vs windowed

#

so that ratio might change when switching

fresh river
#

interesting

true blaze
#

like on my monitor it's 1920x1080 in fullscreen (screen resolution) but it can be 1280x768 in windowed mode.

fresh river
#

are you letting players arbitrarily resize the window?

true blaze
#

no

fresh river
#

wait...1280 by 76_8_?

true blaze
#

it's a predefined range between 1280x720 and 1024x768

fresh river
#

gotcha, one of them laptop sizes

true blaze
#

yes

#

so on a bigger screen in windowed mode it can pick the somewhat unusual 1280x768 for a bit more vertical height

#

and that makes it better on 4:3 (though not perfect)

true blaze
# true blaze

so I can replace this line with cam_id = view_camera[0]; to avoid making my own and everything works the same, bug included

fresh river
#

right yeah i mean, i wasnt saying that would fix the problem just that you dont need to create a whole new view heh

#

but youre in bug report land i think

true blaze
#

yes, thank you for that

#

well damn

fresh river
#

not something you can fix on your end

#

the basic behavior that window_set_fullscreen() should exhibit is that it remembers where the screen was before it was fullscreened

#

since thats typical ux expectation. the fact that centereing it gets nebulously fucky is just buggy behavior on the runner

true blaze
#

and that works fine iif the game starts in windowed mode.
actually I might be able to work around this by setting it to windowed mode first, then setting it to fullscreen one frame later

#

in the meantime I can also report a bug

fresh river
#

this is one of those 2d-game centric nightmares thats not fun to deal with btw, youre not alone everyone has to go through this. especially for pixel art games.

true blaze
#

yeah I figured lol

#

thanks much for the help haha

#

someday I will have camera code that just works every time and I'll never have to look at it again. until the next gamemaker update

fresh river
#

i just make all my games 3d games

#

and its way easier

#

just zoom in or out a smidge based on the display size and window size haha

true blaze
#

one of the rare simplicities of model/vector art games

true blaze
#

well