ViewPorts Views Cameras, Need Help [UNSOLVED]

Petrik33

Member
Hello everybody, could you please help me with scailing, fullscreen mode and else: I am doing game for portrait view of phones so I have maximum view Width of 800 px. So when I test my game on computer of 1280:1024 in full screen it looks normally (can't make a screenshot, so explain here: right resolution and black bars in fullscreen ) and works properly, but I want to add exit to fullscreen mode to have the game in original size streched to display properties, so in my case it's maximum width and minimum Height its all calculated properly but I don't know how to realize it. Here is my code:

Escape pressed:
window_set_fullscreen(false);
surface_resize(application_surface,viewW,viewH);
display_set_gui_size(viewW,viewH);
window_set_size(viewW,viewH);
alarm[0]=1;//Center window

But when I press Escape my game leaves fullscreenmode and becomes even more streched in width axis and nothing works, I mean buttons aren't pressing and else.
The picture of this is screenshot 1.
But strangely when I press on game tab on windows panel the game hides and comes back with proper width and height, black bars and working buttons and else, thats screenshot 2.

Could you please reccomend me a better code of exiting fullscreen mode or help with my problem.
 

Attachments

Catastrophe

Member
Seeing as you don't mind code snippets, I personally just ripped this from reddit and it basically solves all of my screen code regarding resolution and fullscreen, probably solves your problems as well (link in code, because the forums are weird):

Code:
https://www.reddit.com/r/gamemaker/comments/37djxh/help_screen_resolution_options_menu/
Seems overcomplicated and might be designed around bugs that may no longer exist, but hey it works, ya know?
I'm a little bit of a newbie regarding these kinds of mechanics, so if you need further help, mark the topic unsolved so someone else helps out.
 

Petrik33

Member
I've changed the thread a little because I did the same with code. Actually now the problem is I don't understand which property is wrong,
On the attached screenshot you may see number in corners 800-800 are width of camera and window, 997-window height 1280 camera height, but still the game is drawn narrower than 800px making black borders sides. So which property may cause this bug.
Here it the code of Display Manager

Create Event

playable_width=720;
playable_height=1280;
playable_aspRatio=playable_width/playable_height;


max_width=800;
max_height=1400;

viewW=0;
viewH=0;

screenW=display_get_width();
screenH=display_get_height();
var aspRatio=screenW/screenH;

if(aspRatio>=playable_aspRatio) // Add some width
{
viewW=playable_height*aspRatio;
viewW=min(viewW,max_width);
viewH=playable_height;
}

if(aspRatio<playable_aspRatio)
{
viewH=playable_width/aspRatio;
viewH=min(viewH,max_height);
viewW=playable_width;
}


//Check for odd numbers
if(viewW mod 2!=0) viewW++;
if(viewH mod 2!=0) viewH++;

for(var i=0;i<=room_last;i++)
{
room_set_view_enabled(i,true);
camera_destroy(room_get_camera(i,0))
var newCam=camera_create_view((max_width-viewW)/2,(max_height-viewH)/2,viewW,viewH,0,0,1,1,0,0);
room_set_camera(i,0,newCam);
room_set_viewport(i,0,true,0,0,screenW,screenH);
view_set_camera(0,newCam);

}
window_set_size(screenW,screenH);
window_set_fullscreen(true);
surface_resize(application_surface,viewW,viewH);
display_set_gui_size(viewW,viewH);
alarm[0]=1;


room_goto(rm_menuPlay);

Escape button Event
for(var i=0;i<=room_last;i++)
{
room_set_viewport(i,0,true,0,0,viewW,viewH);
}
display_set_gui_size(viewW,viewH);
surface_resize(application_surface,viewW,viewH)
window_set_size(viewW,viewH);
window_set_fullscreen(false);
alarm[0]=1;
 

Catastrophe

Member
Well as said, you should probably mark the topic "(unsolved)" if you found the code I gave unhelpful, this isn't my area of expertise. I just made a drive-by comment that I was hoping would solve the problem since I saw the thread had no answers. That said, I mean, the code linked is so much simpler, so I wonder if it's easier to simply comment out your code and give it a shot, which is what I did with my game since the linked code just worked instantly.

Edit: nvm. Anyways thinking about this a bit more. My hunch would be you should be setting the window size first, and then resizing the surface or (as the reddit suggest the function may be buggy) waiting a frame before doing any functions after first setting the window size.

For example: This is the order, and comments, in the reddit thread:
Code:
case 0: display_reset(aa, vsync); //not too surprising that resetting the display comes first. Only necessary if you give players the option to change aa and vsync in game break;

case 1: window_set_size(width, height); //this is the only function that needs to run on a separate step. I've found it will not work correctly if used in the same step as the other functions break;

case 2: window_set_fullscreen(true/false); //if setting it to fullscreen (true), window_set_size() won't have any effect. break;

case 3: surface_resize(application_surface, width, height);
etc
etc
They do these all in a separate frame to be safe, but as their comments suggest, the window_set_size should be done before just about anything and possibly in a separate step event frame.

Edit: Yeah I should probably stop talking, this just isn't my area of expertise.
 
Last edited:

Petrik33

Member
Well as said, you should probably mark the topic "(unsolved)" if you found the code I gave unhelpful, this isn't my area of expertise. I just made a drive-by comment that I was hoping would solve the problem since I saw the thread had no answers. That said, I mean, the code linked is so much simpler, so I wonder if it's easier to simply comment out your code and give it a shot, which is what I did with my game since the linked code just worked instantly.

Edit: nvm. Anyways thinking about this a bit more. My hunch would be you should be setting the window size first, and then resizing the surface or (as the reddit suggest the function may be buggy) waiting a frame before doing any functions after first setting the window size.

For example: This is the order, and comments, in the reddit thread:
Code:
case 0: display_reset(aa, vsync); //not too surprising that resetting the display comes first. Only necessary if you give players the option to change aa and vsync in game break;

case 1: window_set_size(width, height); //this is the only function that needs to run on a separate step. I've found it will not work correctly if used in the same step as the other functions break;

case 2: window_set_fullscreen(true/false); //if setting it to fullscreen (true), window_set_size() won't have any effect. break;

case 3: surface_resize(application_surface, width, height);
etc
etc
They do these all in a separate frame to be safe, but as their comments suggest, the window_set_size should be done before just about anything and possibly in a separate step event frame.

Edit: Yeah I should probably stop talking, this just isn't my area of expertise.
Well as said, you should probably mark the topic "(unsolved)" if you found the code I gave unhelpful, this isn't my area of expertise. I just made a drive-by comment that I was hoping would solve the problem since I saw the thread had no answers. That said, I mean, the code linked is so much simpler, so I wonder if it's easier to simply comment out your code and give it a shot, which is what I did with my game since the linked code just worked instantly.

Edit: nvm. Anyways thinking about this a bit more. My hunch would be you should be setting the window size first, and then resizing the surface or (as the reddit suggest the function may be buggy) waiting a frame before doing any functions after first setting the window size.

For example: This is the order, and comments, in the reddit thread:
Code:
case 0: display_reset(aa, vsync); //not too surprising that resetting the display comes first. Only necessary if you give players the option to change aa and vsync in game break;

case 1: window_set_size(width, height); //this is the only function that needs to run on a separate step. I've found it will not work correctly if used in the same step as the other functions break;

case 2: window_set_fullscreen(true/false); //if setting it to fullscreen (true), window_set_size() won't have any effect. break;

case 3: surface_resize(application_surface, width, height);
etc
etc
They do these all in a separate frame to be safe, but as their comments suggest, the window_set_size should be done before just about anything and possibly in a separate step event frame.

Edit: Yeah I should probably stop talking, this just isn't my area of expertise.
Oh, this seems to be very helpful, thank you so much, my fault, that I haven't noticed the importance of separating code, gonna try and say how it goes.

Edit: used fully the same code, works nice, BUT the game doesn't get input, I mean mouse buttons aren't doing anything
 
Last edited:
Top