Created
June 9, 2018 21:55
-
-
Save camilacanhete/7fac63a71c26d340cb23e27f25bf6994 to your computer and use it in GitHub Desktop.
GameMaker: Studio mobile display setup (keeping aspect ratio without black bars)
This file contains 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
/* Paste this script inside your room creation code */ | |
view_wview[0] = floor(global.viewWidth); | |
view_hview[0] = floor(global.viewHeight); | |
view_wport[0] = global.maxWidth; | |
view_hport[0] = global.maxHeight; | |
view_xview[0] = (global.idealWidth / 2) - (floor(global.viewWidth) / 2); //csantos: center-align view width | |
view_yview[0] = (global.idealHeight/ 2) - (floor(global.viewHeight)/ 2); //csantos: center-align view height | |
display_set_gui_size(view_wview[0], view_hview[0]); | |
surface_resize(application_surface, view_wview[0], view_hview[0]); |
This file contains 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
/* This script must be executed once, ideally at game start */ | |
var isPortrait = false; | |
//csantos: display variables (ideal width and height is the same as your room size) | |
global.idealWidth = 768; | |
global.idealHeight = 1024; | |
global.maxWidth = display_get_width(); | |
global.maxHeight = display_get_height(); | |
global.aspectRatio = display_get_width()/display_get_height(); | |
global.viewWidth = 0; | |
global.viewHeight = 0; | |
//csantos: portrait | |
if(global.maxWidth < global.maxHeight) { | |
isPortrait = true; | |
global.viewWidth = min(global.idealWidth, global.maxWidth); | |
global.viewHeight = global.viewWidth / global.aspectRatio; | |
} | |
//csantos: landscape | |
else { | |
global.viewHeight = min(global.idealHeight, global.maxHeight); | |
global.viewWidth = global.viewHeight * global.aspectRatio; | |
} | |
var xView = (global.idealWidth / 2) - (floor(global.viewWidth) / 2); | |
var yView = (global.idealHeight / 2) - (floor(global.viewHeight) / 2); | |
//csantos: adjusting for retina displays | |
if((isPortrait && xView > 0) || (!isPortrait && yView > 0)) { | |
global.viewWidth = global.viewWidth*1.25; | |
global.viewHeight = global.viewHeight*1.25; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment