Created
May 28, 2022 22:20
-
-
Save derme302/bdfecf73dec161c88d9a25c760ed728a to your computer and use it in GitHub Desktop.
Automatically set all the views in all your Game Maker Studio 2 rooms so that you only need to call it once at the start of the game.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reference: https://gamemaker.io/en/blog/the-basics-of-scaling-the-game-view | |
function display_scale_all_rooms() { | |
var base_w = 1024; | |
var base_h = 768; | |
var max_w = display_get_width(); | |
var max_h = display_get_height(); | |
var aspect = display_get_width() / display_get_height(); | |
if (max_w < max_h) { | |
// portait | |
var VIEW_WIDTH = min(base_w, max_w); | |
var VIEW_HEIGHT = VIEW_WIDTH / aspect; | |
} | |
else { | |
// landscape | |
var VIEW_HEIGHT = min(base_h, max_h); | |
var VIEW_WIDTH = VIEW_HEIGHT * aspect; | |
} | |
camera_set_view_size(view_camera[0], floor(VIEW_WIDTH), floor(VIEW_HEIGHT)) | |
view_wport[0] = max_w; | |
view_hport[0] = max_h; | |
surface_resize(application_surface, view_wport[0], view_hport[0]); | |
var _check = true; | |
var _rm = room_next(room); | |
var _rprev = _rm; | |
while (_check = true) { | |
var _cam = room_get_camera(_rm, 0); | |
camera_destroy(_cam); | |
var _newcam = camera_create_view((1024 - VIEW_WIDTH) div 2, (768 - VIEW_HEIGHT) div 2, VIEW_WIDTH, VIEW_HEIGHT); | |
room_set_camera(_rm, 0, _newcam); | |
room_set_viewport(_rm, 0, true, 0, 0, VIEW_WIDTH, VIEW_HEIGHT); | |
room_set_view_enabled(_rm, true); | |
if _rm = room_last { | |
_check = false; | |
} | |
else { | |
_rprev = _rm; | |
_rm = room_next(_rprev); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment