• 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!

GameMaker Changing View Port Not Changing Anything

samspade

Member
I was drawing a bunch of variables to the screen to check something else when I noticed that my view port variables didn't seem to match much to anything. So I added some code into change the viewport, and it seems that I can change the view port to whatever I want (including negative numbers) and nothing changes on screen.

Code:
//debug code

var camera_port_width, camera_port_height;

camera_port_width = view_wport[0];
camera_port_height = view_hport[0];

print("Camera Port Width ", camera_port_width);
print("Camera Port Height ", camera_port_height);


//code that changes viewport
var change = 0;
if (keyboard_check(vk_up)) || (keyboard_check(vk_down)) {
    change = keyboard_check(vk_down) - keyboard_check(vk_up);
    view_set_hport(0, view_hport[0] + change);
}
if (keyboard_check(vk_left)) || (keyboard_check(vk_right)) {
    change = keyboard_check(vk_right) - keyboard_check(vk_left);
    view_set_wport(0, view_wport[0] + change);
}
I didn't notice this at first because it isn't actually causing a problem for me, but now I'm curious as to why these variables don't seem to be doing what I think they should.

Does anyone know what is going on?
 

YoSniper

Member
First, check to make sure Views Enabled is checked in the room.

Second, make sure that View 0 is the view in use.

If both of the above are true, and the issue persists, then maybe I don't understand view ports as well as I think.
 

samspade

Member
First, check to make sure Views Enabled is checked in the room.

Second, make sure that View 0 is the view in use.

If both of the above are true, and the issue persists, then maybe I don't understand view ports as well as I think.
Views aren't enabled in the room editor, but I do have them enabled in code. This is my camera's create event:

Code:
#macro VIEW view_camera[0]

view_enabled = true;
view_visible[0] = true;

camera_set_view_size(VIEW, room_width, room_height);
camera_set_view_pos(VIEW, x - camera_get_view_width(VIEW)/2, y - camera_get_view_height(VIEW)/2);
I have other code that resizes the camera as well and all of that works so there is a functioning camera in my room that can have its view modified.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Are we talking about views or view ports here? A view is what the camera sees, a view port is how it's displayed on the screen.


Either way, I suspect that something is overwriting your settings since setting up a few works perfectly fine with three lines of code on my end.

Make a copy of the room this happens in and remove other instances to see if the issue will magically fix itself by doing so. If possible, narrow down the cause of it.

If it happens even if there's just one instance in the room, please post the full info of its object.
 

samspade

Member
View ports - The area of the screen where the camera view will be displayed.

I've reduced the code in the project to the following.

There are three objects in the room, obj_camera_handler, obj_display_info, obj_display_handler_v1. The room itself has 5 sprites on an asset layer which show the edge of the room and the center.

Code:
/// @description Display Info - Show Full Display Info


var window_width, window_height, camera_view_width, camera_view_height, camera_port_width, camera_port_height;
var gui_width, gui_height, application_surface_width, application_surface_height;

window_width = window_get_width();
window_height = window_get_height();
camera_view_width = camera_get_view_width(VIEW);
camera_view_height = camera_get_view_height(VIEW);
camera_port_width = view_wport[0];
camera_port_height = view_hport[0];
gui_width = display_get_gui_width();
gui_height = display_get_gui_height();
application_surface_width = surface_get_width(application_surface);
application_surface_height = surface_get_height(application_surface);

//print scripts are wrapper scripts for show_debug_message that make it easier to type and format
print_start("FULL DISPLAY INFORMATION");

print();
print("DISPLAY VARIABLES");
print("Display Width ", display_get_width());
print("Display Height ", display_get_height());

print();
print("WINDOW VARIABLES");
print("Window Width ", window_width);
print("Window Height ", window_height);

print();
print("CAMERA VARIABLES");
print("Camera View Width ", camera_view_width);
print("Camera View Height ", camera_view_height);
print("Camera Port Width ", camera_port_width);
print("Camera Port Height ", camera_port_height);

print();
print("SURFACE VARIABLES");
print("GUI Width ", gui_width);
print("GUI Height ", gui_height);
print("Application Surface Width ", application_surface_width);
print("Application Surface Height ", application_surface_height);

print();
print("Pixel Interpolation ", gpu_get_tex_filter());

print();
print_end();

Code:
/// @description Camera Handler - Create Event

#macro VIEW view_camera[0]

view_enabled = true;
view_visible[0] = true;

camera_set_view_size(VIEW, room_width, room_height);
camera_set_view_pos(VIEW, x - camera_get_view_width(VIEW)/2, y - camera_get_view_height(VIEW)/2);
Code:
/// @description Center Camera - User Event 0

camera_set_view_pos(VIEW, x - camera_get_view_width(VIEW)/2, y - camera_get_view_height(VIEW)/2);

Code:
#region //1 to set view size 1920 x 1080
if (keyboard_check_pressed(ord("1"))) {
    set_resolution(1920, 1080);
}
#endregion

#region //2 to set view size 960 x 540
if (keyboard_check_pressed(ord("2"))) {
    set_resolution(960, 540);
}
#endregion

var change = 0;
if (keyboard_check(vk_up)) || (keyboard_check(vk_down)) {
    change = keyboard_check(vk_down) - keyboard_check(vk_up);
    view_set_hport(0, view_hport[0] + change);
}
if (keyboard_check(vk_left)) || (keyboard_check(vk_right)) {
    change = keyboard_check(vk_right) - keyboard_check(vk_left);
    view_set_wport(0, view_wport[0] + change);
}
Code:
///scr set resolution
/// @description Set the Resolution of the window, camera, port, and application surfaces
/// @param {int} width
/// @param {int} height

var _new_width    = floor(argument0);
var _new_height = floor(argument1);

window_set_size(_new_width, _new_height);

camera_set_view_size(VIEW, _new_width, _new_height);
view_set_wport(0, _new_width);
view_set_hport(0, _new_height);
window_set_size(_new_width, _new_height);

surface_resize(application_surface, _new_width, _new_height);
display_set_gui_size(_new_width, _new_height);

alarm[0] = 1;
Code:
///alarm[0]
window_center();

with (obj_camera_handler) {
    event_user(0);
}

I can use space bar to print out the debug messages showing what the view port size is. It is definitely change. Regardless of what it changes to, there is no change on my screen. The window takes up the window size, the sprites marking the edges and the center appear in the edges and the center of the window.

Also, since nothing does anything without a keypress, when I push spacebar to get the read out, I wouldn't expect those values to be one thing then, and another thing in the draw event, and they are consistent between frames (e.g. I can hit space bar multiple times and get the same read out).

The only thing I can think of is that GM auto resizes the view port to fit the entire screen.

Edit: I'm pretty sure this is it. I found my own post from October of last year where I went through the same issue - which I apparently forgot. I'm annoyed as I was then, but I guess it is the way it is. In this case, GM auto behavior is actually what I want but I still think GM provided functions should work, or if they're going to be overridden that should be put in the manual so I don't waste so much time trying to debug intended behavior. Or maybe it is and I missed it.
 
Last edited:
Are we talking about views or view ports here? A view is what the camera sees, a view port is how it's displayed on the screen.


Either way, I suspect that something is overwriting your settings since setting up a few works perfectly fine with three lines of code on my end.

Make a copy of the room this happens in and remove other instances to see if the issue will magically fix itself by doing so. If possible, narrow down the cause of it.

If it happens even if there's just one instance in the room, please post the full info of its object.
So is the view port that set the "resolution" of the game?
 

badwrong

Member
If you only have 1 viewport enabled then the dimensions are fairly pointless to even touch. Set them to the window dimensions and that's it.
The way viewport (and scissors which GM doesn't expose) are supposed to work in the pipeline is they define where on the current render target drawing is done.

GM however seems to do some funky stuff with their viewport bounding box and when only 1 viewport is used you really just get the same dimensions as the window.

Personally, I call it a bug because I know how those parameters work directly in something like Vulkan and it is not the same as in GM.
So, you could enable two viewports and suddenly you'll see those values do work. However, an extra viewport enabled is a terrible fix if you do not need to draw things multiple times (potentially based on camera culling).

If your goal is to draw to only a specific area of the window then turn off automatic application surface drawing and handle it yourself in post draw.
Or... double check that you are not confusing the camera view with viewports. It is very common for people to touch view_wport, view_hport, and related functions when they have no reason to.
 

badwrong

Member
So is the view port that set the "resolution" of the game?
The resolution you render at is determined by the render target, which by default is the application surface.
The resolution you display everything at is determined by the size of the game window itself.
Those two things do not have to match, but in most cases they should.
The viewport defines where on the render target you are drawing (or is supposed to). You almost always want your camera view's aspect ration to match the aspect ratio of the viewport so that things are not stretched.
The camera view is where in the gameworld you are looking and transforms that to be drawn to the render target where the viewport defines.
 
The resolution you render at is determined by the render target, which by default is the application surface.
The resolution you display everything at is determined by the size of the game window itself.
Those two things do not have to match, but in most cases they should.
The viewport defines where on the render target you are drawing (or is supposed to). You almost always want your camera view's aspect ration to match the aspect ratio of the viewport so that things are not stretched.
The camera view is where in the gameworld you are looking and transforms that to be drawn to the render target where the viewport defines.
thank you
 
Top