Reputation: 62
I am making a game in GameMaker: Studio. I am attempting to automatically set the view size of the game to the computer's current screen resolution.
I have an initialisation room called room_init. It contains the following code at the start of the game:
///Initialisation Room
//Get size of screen and set size and view of room_main
global.display_w = display_get_width();
global.display_h = display_get_height();
room_set_width(room_main,global.display_w);
room_set_height(room_main,global.display_h);
room_set_view(room_main,0,true,0,0,global.display_w,global.display_h,0,0,global.display_w,global.display_h,0,0,0,0,noone);
window_set_size(global.display_w,global.display_h);
//Go to next room
room_goto_next();
The next room is room_main where the game is played. room_main has the default size of 1024x768, but its room size is changed by the above code.
When I set the room size of room_init to 1366x768 (my screen resolution) the game played in room_main looks like this:
The numbers at the top left show the size of room_main (1366x768).
When I set the room size of room_init to 200x100, the game played in room_main looks like this:
The numbers at the top left still read 1366x768.
I have checked display_get_width() and display_get_height() also and they return 1366 and 768 respectively, regardless of the room size of room_init.
I have looked through the GM: Studio user manual and browsed online for similar questions. I can't find anything that seems to work. Any help would be greatly appreciated.
Upvotes: 2
Views: 3415
Reputation: 71
There is a way to make the resolution actually be dynamic, so it can be changed in-game.
Keep your room called room_init. Give it this creation code: room_goto_next()
Now, make a persistent object, and just add this into its step event:
view_wview[0] = window_get_width()
view_hview[0] = window_get_height()
view_wport[0] = view_wview[0]
view_hport[0] = view_hview[0]
view_hborder[0] = view_wview[0] / 2;
view_vborder[0] = view_hview[0] / 2;
This will make the view size and port size equal the window size, and the view border equal the view size divided by two. This way, your object stays in the center, no matter what the resolution.
Lastly, put the persistent object into room_init, and it will change whenever you change the resolution.
Also, you probably know this, but it's worth mentioning that those numbers in the square brackets represent the view, and can be replaced.
Upvotes: 4