Resurrected Entertainment

Archive for the 'Gamemaker' category

Gamemaker: Resize and Center Window

November 10, 2023

If you have configured the default camera and view-port to be a small size, but you want to resize and center your OS window to more closely match your display resolution, throw this code into an object script and put it in your start-up room.

var _base_w = 640;
var _base_h = 384;

var _display_w = display_get_width();
var _display_h = display_get_height();
var _aspect = _display_w / _display_h;

var _ww, _hh;
if (_display_w < _display_h) {
    //portrait
    _ww = min(_base_w, _display_w);
    _hh = _ww / _aspect;
} else {
    //landscape
    _hh = min(_base_h, _display_h);
    _ww = _hh * _aspect;
}

var _window_size_w = _ww * 2
var _window_size_h = _hh * 2
window_set_size(_window_size_w, _window_size_h)

var _x = (_display_w - _window_size_w) / 2;
var _y = (_display_h - _window_size_h) / 2;

window_set_position(_x, _y)