• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Viewport - wport hport not working

Kisunagi

Member
view_enabled = true;

global.camera_base_view = camera_create_view(0, 0, 360, 640);

view_set_visible(0,true);
view_set_camera(0, global.camera_base_view);
view_set_wport(0, 360);
view_set_yport(0, 640);
view_set_xport(0, 0);
view_set_yport(0, 0);

But this is what I get:
1609505914467.png
 

Kisunagi

Member
I'm sure you meant view_set_hport, judging by the topic.
Oh, my bad. I amended the code. Still same.

view_enabled = true;

global.camera_base_view = camera_create_view(0, 0, 360, 640);

view_set_visible(0,true);
view_set_camera(0, global.camera_base_view);
view_set_wport(0, 360);
view_set_hport(0, 640);
view_set_xport(0, 0);
view_set_yport(0, 0);

Still getting the same output

Anyone can help? It seems to follow my room size instead. When I change the room size to 360x640, the output size changed to 360x640.
Anyone got any idea? I want to code it instead of setting it in the room editor.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Okay so, setting the viewport size will have no visible effect on the game window if you don't set the game window to match, or if you don't have multiple viewports active. WHen you start GameMaker, the window size is set to the size of the viewport as defined in the first room of the game, and if no viewport is defined then the window will be the size of the room. If you then change the viewport size manually in code, you also need to call the corresponding window_set_ functions to change the window size to match.
 

Kisunagi

Member
window_set_function?

But I'm building for mobile.

I bought GMS2 MOBILE.

Multiple viewport active? Is there a way to create a dummy viewport without it affecting the game? That way the window will follow exactly the 1st view port setting?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
It doesn't matter if you're building for mobile... your game is still displayed in a window, and that window still needs to be the correct size. I suggest you read this tech blog series before going any further as it'll help you understand what's going on and what you need to do:

 

Kisunagi

Member
It doesn't matter if you're building for mobile... your game is still displayed in a window, and that window still needs to be the correct size. I suggest you read this tech blog series before going any further as it'll help you understand what's going on and what you need to do:

Does not really help me.

As pointed out by the 2nd article:
The 1st article is about filling the GUI into display of any resolution and look correct whereas;
The 2nd article is about filling the game into display of any resolution and look correct.

Currently I just want to display a window of 360x640 with a room size of 800x800. That's all. I do not even have a game to run yet.

The output is correct when I fill in the viewport setting via room editor.
Now I am struggling with how to do the equivalent via code. I think this is a very BASIC thing but somehow cannot get it done.

1609548978506.png

Below is my attempt via code:

view_enabled = true;

global.camera_base_view = camera_create_view(0, 0, 360, 640);

view_set_visible(0,true);
view_set_camera(0, global.camera_base_view);
view_set_wport(0, 360);
view_set_hport(0, 640);
view_set_xport(0, 0);
view_set_yport(0, 0);

Anyone be so kind to show me exactly how it is done?

Referring above video from a fantastic GMS2 user. She did not really code the viewport. She just config it using the room editor. So not really helping my case either.



UPDATE

I amended my code as per below comment, I can get the window to the size I want but I notice there is distortion in the text displayed compared to above screenshot.
1609551495051.png

Amended code.
1609551512526.png

Looks slight vertically distorted, it is as if the test been squeezed vertically a bit. And it is not drawing at (0,0).
1609552399799.png

Further testing, yes, the view is squeezed top and bottom. I do not understand why.
Left, using code, right using room editor

1609553759922.png

I step debug the game, I notice when using code, the output is actually what I wanted and after looping a few times, it turns to what we see on the left hand side. Weird.
Not solved.
 
Last edited:

Nocturne

Friendly Tyrant
Forum Staff
Admin
I've already told you how to do what you want. Set the window size to the viewport size after setting the viewport. ;)
 

Xerohe

Member
For those still trying to figure this out, I found this line of code in the second link that Nocturne posted:

camera_set_view_size(view_camera[0], floor(VIEW_WIDTH), floor(VIEW_HEIGHT))

You'll need to customize VIEW_WIDTH and VIEW_HEIGHT to your needs. For my purposes, I set a static 'preferredHeight' at 320px, and then calculated the width by multiplying said preferredHeight by window_get_width()/window_get_height();
 
Top