☰ Open Navigation

Latest topics
Hello!!Tue Feb 13, 2018 12:35 pmShizuka
Digital marketing serviceTue Jan 23, 2018 10:24 amwwwww
Classy Games Project IdeasSun Dec 17, 2017 3:16 pmMatita
Awesome Music VideosSun Nov 26, 2017 8:43 pmApril
Whatever WarsMon Nov 20, 2017 9:57 amMrJamieMcC
Welcome VeteransWed Nov 08, 2017 8:29 amMatita
GroupsTue Nov 07, 2017 4:29 pmMrJamieMcC
Low Poly TankMon Nov 06, 2017 8:16 pmMrJamieMcC
What mic do i need?Mon Nov 06, 2017 8:10 pmMrJamieMcC
Moonlit Development GamesSat Nov 04, 2017 12:11 pmDylan
Mentioning UsersSat Nov 04, 2017 11:42 amMrJamieMcC
Ludum Dare 40th RecruitmentTue Oct 31, 2017 11:02 pmMrJamieMcC
Tips on how to approveTue Oct 31, 2017 7:43 pmMatita
Whats your childhood game?Tue Oct 31, 2017 4:56 pmOxayMint

Share
Go down
avatar
Junior Moderator
Posts : 31
Join date : 2017-09-26
View user profilehttp://moonlitdevelopment.blogspot.com.mt/

Simple Dynamic Resolution System

on Tue Oct 24, 2017 1:27 pm
Message reputation : 100% (1 vote)
This simple system lets your game dynamically adjust it's resolution based on the display of the device displaying it. This can be useful if you have a game you'd like people to try out on various different display sizes, and it's especially useful if you're simply working on a prototype and want to have it be able to adjust depending on the display you're currently using.

Below is how to implement the system in your project. 

An explanation of what is happening can be found afterwards should you be interested.

The system is simple;

Create an object and name it Resolution_Manager.
In the Create Event for the Resolution_Manager place the following; 

Code:
/// @description Initiate Resolution
ideal_width = 0;
ideal_height = 1080;

aspect_ratio = display_get_width()/display_get_height();

ideal_width = round(ideal_height*aspect_ratio);

if (ideal_width & 1){
   ideal_width += 1
}

for (var i = 1; i <= room_last; i++){
   if room_exists(i){
      view_set_wport(0,ideal_width)
      view_set_hport(0,ideal_height)
   }
}
surface_resize(application_surface, ideal_width, ideal_height);
window_set_size(ideal_width, ideal_height);
window_set_fullscreen(true);
room_goto_next();

Place the Resolution_Manager in an empty room - make sure that this is the first room your game opens when it is executed!

Afterwards, create an object and call it Camera.
In the Create Event of the Camera place the following;
Code:
/// @description Create Camera
camera = camera_create();
global.zoom_level = 1;

var viewmat = matrix_build_lookat(x, y,-1000,x, y,0,0,1,0);
var projmat = matrix_build_projection_ortho(ResolutionManager.ideal_width * global.zoom_level,ResolutionManager.ideal_height * global.zoom_level,1,32000);

camera_set_view_mat(camera, viewmat);
camera_set_proj_mat(camera, projmat);

view_camera[0] = camera;


In the Step Event of the Camera place the following;
Code:
/// @description Update Position
var viewmat = matrix_build_lookat(x, y,-100,x, y,0,0,1,0);
camera_set_view_mat(camera, viewmat);




How does it work?
Essentially, the resolution manager figures out the ideal aspect ratio and resolution based on the device's display. Once that's complete, it adjusts the size of the view port within GMS 2 to the ideals chosen. In this instance, I have chosen the ideal height to be 1080 which will make the game port fit that specification. You can likely add a way for the ideal height to adjust based on the display as well - however, this gives you a bit of control over what the resolution will be to let you plan ahead as you work. 

Once the resolution manager is done then it moves over to the next room, where the Camera object will set up a GMS 2 camera to use. This GMS 2 camera will be centered on the Camera object, allowing you to move the Camera object as required. So if you want the camera to follow a player, simply set up the Camera object to follow the player's Avatar.


There are probably a few issues that might come up and you will most likely need to make a few modifications to make the system work with your project - however hopefully this will help get you started!

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Personal Game Development Blog: https://www.moonlitdevelopment.com/
Back to top
Permissions in this forum:
You cannot reply to topics in this forum