Browser width, window width set-up - nothing works!

Focksbot

Member
Right. Where to begin?

I think what I want is fairly simple: to draw to my GUI layer and have that layer remain in the same place while allowing the player to resize the window or the browser. OK?

So in my create event I have:
GML:
w = browser_width;
h = browser_height;
Then in my step event I detect any changes in browser size, which triggers an alarm:
Code:
if (browser_width != w || browser_height != h)
    {
    alarm[0] = room_speed;
    }
One second later, the alarm resets my w and h variables to the new browser-size:
Code:
w = browser_width;
h = browser_height;
Now, for my draw GUI event, I ask it to draw the title in the centre of the browser window, and then draw lines either side of it:

Code:
draw_text(w/2 - string_width(title)/2, h/2 - (string_height(title)/2), title);

var lineY = h/2 + (string_height(title)/2 * 0.4);

draw_line(0, lineY, w/2 - string_width(title)/2 - 20, lineY);
draw_line(w, lineY, w/2 + (string_width(title)/2 + 20), lineY);
I've also added some extra code to help me work out what's going on with all these numbers while I troubleshoot:

Code:
draw_text(50, 50, w);
draw_text(50, 80, window_get_width());
draw_text(50, 110, browser_width);
draw_text(50, 140, mouse_x);
Now, what do I find?

1) Firstly, 'w' does not update to browser_width. That's not happening. It stays static.
2) If I preview it as an application and resize the window, the GUI layer resizes in line with the window. If I preview it in HTML and resize the browser, it does not.
3) window_get_width is inaccurate, whether I run it as an application or on a browser. The window width should be the same as the viewport on launch. The viewport is 1024. However, the window_get_width returns as 972. The same is true of browser_width if I run it as an application. Neither function seems to return the actual width of the window or application surface.

This means that the GUI layer doesn't fill the full space and my title (which ought to be in the center) is drifting off to the left.

Any help appreciated.

*edit*

OK, I see why w doesn't update. That's my bad. Help with why the window and browser width are inaccurate would be appreciated.
 
Last edited:

Focksbot

Member
OK, so I changed my creation code to this:

GML:
window_set_size(1024, 768);

w = window_get_width();
h = window_get_height();
Nothing else alters 'w'. Nothing.

And yet 'w' returns as 972. Come on, someone help me out here. Where is it getting 972 from? I have literally told it at the start of the game to make it the equal of window_get_width() after setting the window size, and instead it's just pulling a number out of the air?

So I added a back-up in the step event:

Code:
if mouse_check_button(mb_right) w = window_get_width();
Now if I click it, it corrects 'w' and places the GUI properly. But why can't it do this as part of the create event?
 
Top