GameMaker Scaling Guide from GM2 page is wrong

Carloskhard

Member
In THIS TUTORIAL they tell you to use this code to do a full screen scaling:
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]);

The idea seems ok exept the fact that they use "min", so if the width of the screen is less than the base width(in a portrait way in this case), the camera view size will use the width of the screen which will not show the entire width of the room(The image will be cut in height and width, which is stupid since the idea is to only reduce or expand one of the two). Even the tutorial example is wrong since the say:
For example, take our 1024x768 game on an 800x480 device. We will set the viewport height to be 768
..when clearly the code will run landscape mode and will choose the min betweem 768 and 480,(which is not 768 as the tutorial states...) cropping a big chunk of the original height view.
Doesn't anyone tried out the tutorial code before posting it?
Also the tutorial could add more simple stuff like saying that you can center the new image with a simple line, and the code for doing this for every room is also very messy and doesn't explain enough, like for example mentioning that this woulnd't work if you don't have persistent rooms,which you need to say in a guide like that or you will confuse a lot of people.

Anyway, here is my take on the same tutorial but working correctly and also adding camera centering with just one line:
var base_w = //Your base width here
var base_h = //Your base height here
var max_w = display_get_width();
var max_h = display_get_height();

var aspect = max_w / max_h;
if (max_w < max_h)
{
// portait (Keep width / Crop height)
var VIEW_WIDTH = base_w;
var VIEW_HEIGHT = VIEW_WIDTH / aspect;
camera_set_view_size(view_camera[0],floor(base_w), floor(VIEW_HEIGHT))
camera_set_view_pos(view_camera[0],0,-(VIEW_HEIGHT-base_h)/2);
}
else
{
// landscape (Keep Height / Crop Width)
var VIEW_HEIGHT = base_h;
var VIEW_WIDTH = VIEW_HEIGHT * aspect;
camera_set_view_size(view_camera[0],floor(VIEW_WIDTH), floor(base_h))
camera_set_view_pos(view_camera[0],-(VIEW_WIDTH-base_w)/2,0);
}

view_wport[0] = max_w;
view_hport[0] = max_h;
surface_resize(application_surface, view_wport[0], view_hport[0]);


I hope someone fix that since I've been so confused thinking I was doing something wrong and surely a lot of other people too.
Thanks!
 
Last edited:
Top