Can't figure out aspect ratio resizing

Q

Queble

Guest
Hey all!

I am fairly new to gms2, and am currently creating a portfolio project for Android.

My most recent problem, is that when I run the game on my android phone, I get these blinking white bars on the edges of the screen, which are obviously undesired.
I have done a lot of reading/tutorials on this subject, and realized that the game's aspect ratio/dimensions dont match the device's.
(I could technically scale my camera to the dimensions of my phone, but this would obviously cause problems on other people's devices).


So basically I want to re-scale the game to dynamically fit the device, but I am completely lost on how to do this :/
I watched all of the Pixelated Pope's tutorials on this about 4 times each, and although I understand the basics, idk how to implement them into GMS2 through actual code.

If anyone can direct me to a tutorial that walks through how to set a dynamic scaling script that will fit the game to any size phone screen, or even explain how I can do this, -
that would be extremely appreciated :)


Thank you in advance for your time.

-Queble
 

xS89Deepx

Member
Try this and see if this work for you, work great on bigger resolutions example 1440p but i haven't tried on small ones...

Create a script -

Script_Scaling

// Resizing to all devices 1280x720 or you can try this 1024x768...
var base_w = 1280;
var base_h = 720;
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((1280 - VIEW_WIDTH) div 2, (720 - 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);
}
}


Make a object - Object_Scaling

Create Event
- alarm[0]=100;
GameStart Event - Script_Scaling();
Alarm0 Event - room_goto_next();

Now create a first room 1290x720 and than put a Object_Scaling in the first room...
 
Last edited:

xS89Deepx

Member
When you create first room with resolutions of 1290x720, next room must be 1280x720, than play the game to see if worked or try 1024x768 i haven't tried this yet...I'm not expert in coding but this what i can HELP :)
 
Q

Queble

Guest
When you create first room with resolutions of 1290x720, next room must be 1280x720, than play the game to see if worked or try 1024x768 i haven't tried this yet...I'm not expert in coding but this what i can HELP :)
Ok, thanks a ton!
I will try this as soon as I get the chance
 
Top