How to make the window keep the aspect ratio? 🙏
Viewing post in Window freeze fix comments
Using math, e.g. this instead of regular resize logic in demo’s Step
if (window_frame_get_visible()) {
var w = window_frame_get_width();
var h = window_frame_get_height();
if (w > 0 && h > 0 && surface_exists(application_surface)
&& (window_get_width() != w || window_get_height() != h)
) {
var gameWidth = 320, gameHeight = 240;
var scale = min(w/gameWidth, h/gameHeight);
var outWidth = gameWidth * scale;
var outHeight = gameHeight * scale;
var outX = (w - outWidth) div 2;
var outY = (h - outHeight) div 2;
// resize room (since we don't use views):
room_width = outWidth; room_height = outHeight;
// resize the game inside the frame-window to fit it's size:
window_frame_set_region(outX, outY, outWidth, outHeight);
// also resize application_surface:
surface_resize(application_surface, outWidth, outHeight);
}
}