SOLVED Panning View jitter Issue

Xer0botXer0

Senpai
Hi guys,

Update:

So I've moved over to the spacebar + left click combo for panning the screen, it seems to work great besides for jitter. Here's the code, I thought perhaps slight movements of the hand caused the jitter but infact after moving the mouse and stop moving while still having the combo pressed it jitters. I draw the x/y coordinates on screen and the view_x/yview values are jumping around, but very little.

GML:
///Test Camera location
 
if keyboard_check(vk_space) && mouse_check_button(mb_left)
{
    if prev_x != mouse_x
    {
        if prev_x > mouse_x
        {
            xview += floor(prev_x - mouse_x);
        }
        if prev_x < mouse_x
        {
            xview -= floor(mouse_x - prev_x);
        }
    }
    
     if prev_y != mouse_y
    {
        if prev_y > mouse_y
        {
            yview += floor(prev_y - mouse_y);
        }
        if prev_y < mouse_y
        {
            yview -= floor(mouse_y - prev_y);
        }
    }   
}
prev_x = mouse_x;
prev_y = mouse_y;
--------------
So I needed to implement zoom/pan functionality to help me decide if I'm gonna create two rooms or stick to one room and just zoom in to the scenes.

And I've had horrible experiences with views, so beside from reading the documentation which hasn't helped me very much I've decided to keybind incrementing/decrementing values to view_xview, view_yview, view_hview, view_wview, view_xport, view_yport, view_wport and view_hport..

With that I've concluded that view_x/yview moves the visible window around the view port.
The view_w/hview zooms in/out, I do have a question about this or an issue which I'll ask in a moment.
The view_x/yport doesn't do anything when I increment/decrement their values (+/- 30) ? If I remember correctly that only works before entering a room or restarting a room.
View_w/hport I haven't tested yet. I assume it would zoom in as well ? is it similar to image_xscale/image_yscale ? but of the room view ?

And back to zooming in and out with view_w/hview, it seems to zoom in and out on the view_x/yview position instead of zooming in on the center. So my guess is it's sort of like cropping the view by the width and height.

So far I'm happy with my tests, I'm going to do some proper key binding now like hold space + left clicking and dragging will activate a boolean which when active will pan the camera around, zooming will be hold space + mouse scroll, but how would I zoom in to the center instead of on the x/y coordinates of the view ? I assume some sort of offset.

Finally I do wonder, is there a way to actually change the game window width/height itself ? like if my main menu is w:1024/4 h:800/1.5 and then I could change it back to the larger resolution when in-game and full screen. Or alternatively a way to resize the window with the mouse on border ?
 
Last edited:

Nidoking

Member
The view is the portion of your room that should be visible. The port should be where that portion of your room appears within the game window. So, if you imagine looking through a rectangular hole in a wall into your room, moving the view is like looking through the hole at a different angle, letting you see a different portion of the room. The port is like moving where the hole is on the wall, without actually changing what's visible through it.

Working in GM 8, I remember having some difficulties with the view parameters if I hadn't enabled views in the room in the editor - enabling views at runtime didn't work for me. However, I could definitely change the port on the fly, and even used that ages ago to create an effect like a character holding a lantern using only a single overlay sprite, without having to darken the entire room.
 

Xer0botXer0

Senpai
Solved:

GML:
 if keyboard_check(vk_space) && mouse_check_button_pressed(mb_left)
{
    prev_x = mouse_x;
    prev_y = mouse_y;

///Test Camera location
 
if keyboard_check(vk_space) && mouse_check_button(mb_left)
{
    if prev_x != mouse_x
    {
        if prev_x > mouse_x
        {
            xview += floor(prev_x - mouse_x);
        }
        if prev_x < mouse_x
        {
            xview -= floor(mouse_x - prev_x);
        }
    }
    
     if prev_y != mouse_y
    {
        if prev_y > mouse_y
        {
            yview += floor(prev_y - mouse_y);
        }
        if prev_y < mouse_y
        {
            yview -= floor(mouse_y - prev_y);
        }
    }   
}

}
-----

Interesting, I need to play around with the port more.. because I really don't understand why the port has x/y coordinates then.
I'm assuming.. that maybe it's there for when a person has multiple views.. and setting the view port w/h smaller and moving the port to a different positon on screen.. ah for like.. split screen.
 
Last edited:

Nidoking

Member
Like I said, I used it to implement a darkness effect. Drawing a giant black sprite with a tiny hole for the character would have slowed down the game, but by making a tiny view that covered the character and a sprite that just filled that view with darkness, it ran at normal speed, and I updated the port so that the view would always appear in the correct location on screen relative to where the full screen view would be. I could switch between the full view and the tiny view with a keystroke.
 
Top