Windows Moving view code issue

zendraw

Member
when i try to move the view with this code
Code:
//move view------------------------------------------------------
if (mbm_p)
{
    xdrag=floor(mouse_x);
    ydrag=floor(mouse_y);
    xview=floor(view_xview);
    yview=floor(view_yview);
}

if (mbm)
{
    view_xview=clamp(xview+floor(xdrag-mouse_x), 0, room_width-view_wview);
    view_yview=clamp(yview+floor(ydrag-mouse_y), 0, room_height-view_hview);
}
the view shuld get dragged around, and it does. but the problem is that it stutters as if it wants to be in two places at once. and this has somthing to do with moving the view itself and mouse_x/y becouse when i look at the xdrag-mouse_x, without applying the code in if (mbm) the value calculates normally, but if i run the code in if (mbm) the value constantly shifts betwean two values, making the screen stutter.
mbm is mouse_check_button and mbm_p is mouse_check_button_pressed.

any idea how to fix this?
 

marasovec

Member
Here is my code for dragging (GMS 1.4)
Create Event:
Code:
mx = 0;
my = 0;
Step Event:
Code:
if mouse_check_button_pressed(mb_middle)
    {
    mx = mouse_x;
    my = mouse_y;
    }

if mouse_check_button(mb_middle)
    {
    view_xview += mx - mouse_x;
    view_yview += my - mouse_y;
    }
I hope it'll help you somehow
 

zendraw

Member
well i kinda fixed it alredy, thanx for the effort tho. does your code actually work? like dragging the view, it seems as if it wuldnt work imo.

Code:
//move view------------------------------------------------------
if (mbm_p)
{
    xdrag=floor(mouse_x-view_xview);
    ydrag=floor(mouse_y-view_yview);
}

if (mbm)
{
    var ref=0;
    var cvx=floor(mouse_x-view_xview);
    var cvy=floor(mouse_y-view_yview);
    if (xdrag!=cvx) {view_xview=clamp(view_xview+floor(xdrag-cvx), 0, room_width-view_wview); ref=1};
    if (ydrag!=cvy) {view_yview=clamp(view_yview+floor(ydrag-cvy), 0, room_height-view_hview); ref=1};
    xdrag=cvx;
    ydrag=cvy;
}
 
Top