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

GML Peculiar problem envolving Room Size and View

A

André Guilherme

Guest
Hey everyone! Hope i'm posting this in the right place...

Here's the problem:

I've been testing art and game mechanics in a room called rm_test.
The room is 1366x768.
I also have a obj_camera which controls the view's x, y, width and height, and view_port dimensions as well.
The width and height values of the view are 820x481 and the values of the view_port are 1366x768 (all set in the create event of obj_camera).

This works wonderfully (as seen in one of the images below - the one with most art assets).

Eventually i tried to create a new level from the ground up.
So i created a new room -- rm_stage1 -- and started to set dimensions and a few objects and tested the room.
The resolution was weird and everything that was drawn on the GUI layer was out of place.

I've googled it and tried a few alternatives, like reseting application surface and setting gui display size, but nothing worked and I didn't found much info.

Right now I recreated the room to have 1500x768 and i'm the sure the problem has to do with room size and something else (There's an image of this result as well)
What I don't get is why the view width and height (or/and the view port width ad height) values are changing or not being applied correctly, when everything ran smoothly on the rm_test.

Here's the camera code:
///Activate Camera's View

if !view_enabled
{
view_visible[0] = true;
view_enabled = true;
}

//Screen measurements

max_width = 1366;
max_height = 768;

zoomOut_width = 911;
zoomOut_height = 512;

normal_width = 820;
normal_height = 461;

width = normal_width;
height = normal_height;

//Width and Height, X and Y of View Port (Dimensions of view on screen)

view_wport[0] = 1366; //So it fills the screen
view_hport[0] = 768; //So it fills the screen
view_xport[0] = 0; //So it's in the left upper corner of the screen
view_yport[0] = 0; //So it's in the left upper corner of the screen

//Initial View Position

x = 0;
y = 0;

//Movement Variables

target_x = 0;
target_y = 0;

x_speed = 0;
y_speed = 0;

max_x_spd = 16;
max_y_spd = 16;

accel = 2;
fric = 0.1;

out_of_bounds_x = false;
out_of_bounds_y = false;

///View X and Y

if (mouse_check_button(mb_right))
{
target_x = (obj_player.x+((mouse_x-obj_player.x)/4)) - (view_wview[0]/2.5);
target_y = (obj_player.y+((mouse_y-obj_player.y)/3)) - (view_hview[0]/2);
}
else
{
target_x = (obj_player.x+((mouse_x-obj_player.x)/10)) - (view_wview[0]/2.5);
target_y = (obj_player.y+((mouse_y-obj_player.y)/10)) - (view_hview[0]/2);
}

//Zoom
scr_view_zoom();

//Apply coordinates to view 'x' and 'y'
view_xview[0] = x;
view_yview[0] = y;

///Control View

//Width and Height

view_wview[0] = width;
view_hview[0] = height;

//View Limits (Edges of room)

if (view_xview[0] < 0)
{
out_of_bounds_x = true;
view_xview[0] = 0;
}
else
if (view_xview[0] > room_width - width)
{
out_of_bounds_x = true;
view_xview[0] = room_width - width;
}
else
{
out_of_bounds_x = false;
}

if (view_yview[0] < 0)
{
out_of_bounds_y = true;
view_yview[0] = 0;
}
else
if (view_yview[0] > room_height - height)
{
out_of_bounds_y = true;
view_yview[0] = room_height - height;
}
else
{
out_of_bounds_y = false;
}

(IN END-STEP)
///Follow player smoothly

x += (target_x - x) * 0.1;
y += (target_y - y) * 0.1;

Does anyone know what might be causing this?
Thanks in advance!
 

Attachments

S

Sinaz20

Guest
Can we see the contents of scr_view_zoom()?

Also, maybe bring up the two rooms in the editor next to each other and double check all the settings-- make sure your views are actually turned on, and look for numerical typos.

For after we solve this problem, you might consider looking into room inheritance. Rather than set up view settings in every room, you just make a master parent room that dictates this stuff, then have all your game rooms inherit from that room.
 
A

André Guilherme

Guest
Hey there! Thank you for your input!

The rooms definition are all the same for both rooms, except dimensions.
Views are enabled and visible on both rooms, but they are activated by code as well, in the obj_camera.

Here's the code for scr_view_zoom():
//Zoom In or Out of the specified resolution for both 'modes' (when holding or not the left mouse button)

var zoom_spd = 100; //Lower values result in higher speed

if (mouse_check_button(mb_right))
{
//Zoom Out
/*WIDTH*/
if (width < zoomOut_width)
{
width += (width / zoom_spd);
//These next lines of code are a fail safe so the view doesn't get stuck in zooming in and zooming
if (width + (width / zoom_spd) > zoomOut_width)
{
width = zoomOut_width;
}
}
/*HEIGHT*/
if (height < zoomOut_height)
{
height += (height / zoom_spd);

if (height + (height / zoom_spd) > zoomOut_height)
{
height = zoomOut_height;
}
}

//Zoom in
/*WIDTH*/
if (width > zoomOut_width)
{
width -= (width / zoom_spd);

if (width - (width / zoom_spd) < zoomOut_width)
{
width = zoomOut_width;
}
}
/*HEIGHT*/
if (height > zoomOut_height)
{
height -= (height / zoom_spd);

if (height - (height / zoom_spd) < zoomOut_height)
{
height = zoomOut_height;
}
}
}
else
{
//Zoom Out
/*WIDTH*/
if (width < normal_width)
{
width += (width / zoom_spd);

if (width + (width / zoom_spd) > norma_width)
{
width = normal_width;
}
}
/*HEIGHT*/
if (height < normal_height)
{
height += (height / zoom_spd);

if (height + (height / zoom_spd) > normal_height)
{
height = normal_height;
}
}

//Zoom In
/*WIDTH*/
if (width > normal_width)
{
width -= (width / zoom_spd);

if (width - (width / zoom_spd) < normal_width)
{
width = normal_width;
}
}
/*HEIGHT*/
if (height > normal_height)
{
height -= (height / zoom_spd);

if (height - (height / zoom_spd) < normal_height)
{
height = normal_height;
}
}
}

I've tried something that I think may be related to room inheritance...
I've started the game in another room I have set up (rm_mainmenu) which is 1366x768 and from there you can go to the rm_stage1, and the result is different. Apart from the pause menu, which is not centered (it's being drawn on the GUI layer btw), everything seems fine.

So, from what i gather, some definitions of the game are set at game start - application surface and maybe gui layer size as well...
But can i change them?
I've tried before and nothing happened, but I could've been doing something wrong...

Thanks again!

EDIT: The pause menu was not centered because of unrelated code, it's been fixed since. But the problem with the game resolution still persists when I start the game with rm_stage1.
I've found a workaround by starting the game in the rm_mainmenu, but I'd still like to understand what's happening...
 

Attachments

Last edited by a moderator:
A

André Guilherme

Guest
Ok, I don't know what happened but the problem it's not happening anymore, even when I start the game in rm_stage1.
Thank you for the help, and sorry to bother the forum with flickering problems and unknown solutions :s
 
Top