Windows What is the right way to use the following: window_set_size, surface_resize, window_center()

Owly

Member
Hello! I'm puzzled about some aspects of these functions. I'm creating a game that doesn't use any special views, basically what happens in the 1024x768 room is what you see, and all you see. Here is what I think and please let me know if I'm doing it right:

window_center() is to be used WITHIN an alarm AFTER going from fullscreen mode to window mode, is that correct?

window_set_size(1024,768) is to be used when going from fullscreen to window mode. Is that correct? Or should it also be used when going to fullscreen? Oo Sounds silly but I don't know. Must be used always when going to window mode? Are there exceptions? Are there other uses?

(Extra question with regards to this: what is the best way when going from fullscreen to window mode -- to make sure that the window created is as big as it can be, while still keeping the aspect ratio of 4/3 (1024x768)? Seeing that people use different native resolutions...)

surface_resize -- when is that used? Is it used when going from fullscreen mode to window mode? Must I use it if I don't have any special surfaces used, only the application surface? Does the following make sense: surface_resize(application_surface1024,768)?


So having said all this, does this make sense:

CREATE EVENT
if (!ini_read_string("general","fullscreen","0"))
{
window_set_fullscreen(false);
window_set_size(1024,768);
surface_resize(application_surface,1024,768);
alarm[0]=1
}
else window_set_fullscreen(true);

ALARM 0
if !window_get_fullscreen()
{
window_center();
}

Am I doing it right? What am I missing?
Thanks in advance!
 

FoxyOfJungle

Kazan Games
Your code needs tweaking, but, to go in window mode and full screen mode, use this:
GML:
window_set_fullscreen(!window_get_fullscreen());
All your other questions are very clear and explicit in the manual, see:
Go to: Search, and write the function that you need to know about.
You can also click with the middle mouse button in a function in the code editor to get the info immediately. ;)
 

Owly

Member
Your code needs tweaking, but, to go in window mode and full screen mode, use this:
GML:
window_set_fullscreen(!window_get_fullscreen());
All your other questions are very clear and explicit in the manual, see:
Go to: Search, and write the function that you need to know about.
You can also click with the middle mouse button in a function in the code editor to get the info immediately. ;)
Thanks, but I consulted the manual before posting here, and found it lacking, or at least it didn't offer information that directly answers my specific questions as formulated in my post, or I'm a bit unsure and require some further feedback that goes beyond the manual. For instance, window_center() --> is it necessary to use it when going from fullscreen to window? The manual doesn't answer it, or if it does, it's not clear to me. And vice versa -- do you need to use it when going from window mode to fullscreen?

The same goes with the other questions, do I need to use surface_resize even when I'm not using any special views?

Thanks for the tip regarding window_set_fullscreen(!window_get_fullscreen()); -- this is very nice, very elegant.
 

FoxyOfJungle

Kazan Games
You do not need everything to be to the letter, just understand the logic and draw the conclusions of what should or should not happen.

window_center() is used only to center the window, in window mode.
It is not necessary and should not be used when going from window mode to fullscreen.
surface_resize() is for resize a surface, you can resize the application_surface or any other previously created surface.

I have a script for low resolution games (pixel art) , but can be used in any games:

GML:
zoom=1;
max_zoom=1;
global.ideal_width=0;
//global.ideal_height=(display_get_height()/2);//<--- 1080/4=270, 270*2=540    //270 //540
global.ideal_height=270;


//Aspect ratio
aspect_ratio = display_get_width()/display_get_height();

//Calculate new ideal width.
global.ideal_width=round(global.ideal_height*aspect_ratio);
//global.ideal_height=round(global.ideal_width/aspect_ratio);

global.ideal_width=round(global.ideal_width);
global.ideal_height=round(global.ideal_height);

if(global.ideal_width & 1) global.ideal_width-=1;
if(global.ideal_height & 1) global.ideal_height-=1;

max_zoom = floor(display_get_width()/global.ideal_width);

//Setup all the view ports in all rooms
global.Main_Camera = camera_create_view(0,0,global.ideal_width,global.ideal_height,0,noone,0,0,0,0);
camera_set_view_size(global.Main_Camera,global.ideal_width,global.ideal_height);

for(var i=1; i<= room_last; i++)
{
    if(room_exists(i))
    {   
        room_set_view_enabled(i,true);
        room_set_viewport(i,0,true,0,0,global.ideal_width,global.ideal_height);
        room_set_camera(i,0,global.Main_Camera);
    }
}

surface_resize(application_surface,global.ideal_width,global.ideal_height);
display_set_gui_size(global.ideal_width,global.ideal_height);
window_set_size(global.ideal_width*zoom,global.ideal_height*zoom);

alarm[0]=1; //Center Window
alarm[1]=5; //Go to next room
 

Owly

Member
You do not need everything to be to the letter, just understand the logic and draw the conclusions of what should or should not happen.

window_center() is used only to center the window, in window mode.
It is not necessary and should not be used when going from window mode to fullscreen.
surface_resize() is for resize a surface, you can resize the application_surface or any other previously created surface.

I have a script for low resolution games (pixel art) , but can be used in any games:

GML:
zoom=1;
max_zoom=1;
global.ideal_width=0;
//global.ideal_height=(display_get_height()/2);//<--- 1080/4=270, 270*2=540    //270 //540
global.ideal_height=270;


//Aspect ratio
aspect_ratio = display_get_width()/display_get_height();

//Calculate new ideal width.
global.ideal_width=round(global.ideal_height*aspect_ratio);
//global.ideal_height=round(global.ideal_width/aspect_ratio);

global.ideal_width=round(global.ideal_width);
global.ideal_height=round(global.ideal_height);

if(global.ideal_width & 1) global.ideal_width-=1;
if(global.ideal_height & 1) global.ideal_height-=1;

max_zoom = floor(display_get_width()/global.ideal_width);

//Setup all the view ports in all rooms
global.Main_Camera = camera_create_view(0,0,global.ideal_width,global.ideal_height,0,noone,0,0,0,0);
camera_set_view_size(global.Main_Camera,global.ideal_width,global.ideal_height);

for(var i=1; i<= room_last; i++)
{
    if(room_exists(i))
    {
        room_set_view_enabled(i,true);
        room_set_viewport(i,0,true,0,0,global.ideal_width,global.ideal_height);
        room_set_camera(i,0,global.Main_Camera);
    }
}

surface_resize(application_surface,global.ideal_width,global.ideal_height);
display_set_gui_size(global.ideal_width,global.ideal_height);
window_set_size(global.ideal_width*zoom,global.ideal_height*zoom);

alarm[0]=1; //Center Window
alarm[1]=5; //Go to next room
Hey! Okay, first of, thanks for fully answering my query regarding window_center() :) I feel so much better. I'll test your code later and see if I understand it. But one last question remains, if I may. window_set_size is used for setting the size of the WINDOW when going to window mode, I get that, so the only last thing to query is: why do I need to use the surface_resize() thingie if I don't use any special surfaces? :( I never even created any -- doesn't the regular application surface that is already there anyway automatically fits itself into the new window? What happens if I don't use this function? Again, many thanks Foxy!

EDIT: I don't even use special cameras, why do I need to use the functions that fiddle with camera? What happens if I don't fiddle with "room_set_camera" and "viewports"? :(
 

FoxyOfJungle

Kazan Games
why do I need to use the surface_resize() thingie if I don't use any special surfaces?
You do use a standard built-in surface, the application_surface, it is a surface that draws the entire game screen, if it is not resized, it will look strange.

I don't even use special cameras, why do I need to use the functions that fiddle with camera? What happens if I don't fiddle with "room_set_camera" and "viewports"?
You said you don't use cameras, but you do, you just didn't modify them (built-in camera), so the script does that.
The camera is responsible for viewing a room region.
 
Top