• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code How To Use window_center() ?

Z

Zeralith

Guest
Hey guys,

I'm kinda new to GameMaker, in general, but I cannot for the life of me get window_center() working in GameMaker Studio 2.

I understand that window_center() needs to happen at least 1 Step after a window_set_size() or a window_set_position() is called.

Can anyone let me know how to get window_center() working? Thank you!

Here is my Rooms, Object, and Code:

I have 2 Rooms called "rmBootStrap" and "rmTitleScreen" and made them both 512x288 in size.

I have an Object called "oBootStrap"

I put oBootStrap into rmBootStrap.

Here is the code in oBootStrap:

CREATE:
Code:
if !(window_get_fullscreen()){
    window_set_size(1024, 576); // Set the size to double
}

alarm[0] = 2;
ALARM 0:
Code:
if !(window_get_fullscreen()){
    window_center(); // This is not working
}

//show_message("alarm 0 is working!");

instance_destroy();
DESTORY:
Code:
// Go to the Title Screen
room_goto(rmTitleScreen);
 
Z

Zeralith

Guest
Hey guys,

For now I'm just using the following code, which does seem to be working correctly... but I still do not understand why window_center() is not working for me:

ALARM 0:
Code:
if !(window_get_fullscreen()){
    //window_center(); // This is not working
    global.MonitorW = display_get_width();
    global.MonitorH = display_get_height();
    //show_message(string(global.MonitorW) + "x" + string(global.MonitorH));
    global.Xoffset = (global.MonitorW - window_get_width()) / 2;
    global.Yoffset = (global.MonitorH - window_get_height()) / 2;
    //displayXOString = "Xoffset: " + string(global.Xoffset);
    //displayYOString = "Yoffset: " + string(global.Yoffset);
    //show_message(displayXOString + " --- " + displayYOString);
    window_set_position(global.Xoffset, global.Yoffset);
}

//show_message("alarm 0 is working!");

instance_destroy();
 
Top