• 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 [Solved] Camera snapping to previous location when moving after moving it to other places

K

Konstamonsta

Guest
Edit 1: Guess i just needed to post it here to change my perspective on the thing.
Since i use
Code:
x += floor((xTo-x)/5);
y += floor((yTo-y)/5);
i had to add
Code:
x = viewposX;
y = viewposY;
in the initialization of the variables in my Global Right Down method.



I have two objects which both have a method that moves the camera.
The first is my regular camera moving when the right mouse button is held down.
The second one is to let the view jump between different objects in the room.

Individually these methods work just fine, however when i jumped to a point on the map and then try my drag and move method it jumps back the the previous position before resuming the regular movement

Any idea what might cause this?

Movement method (Global Right Down)
Code:
cam = view_get_camera(0);

vwidth = camera_get_view_width(cam);
vheight = camera_get_view_height(cam);
viewposX = camera_get_view_x(cam) + (vwidth/2);
viewposY = camera_get_view_y(cam) + (vheight/2);

direction=point_direction(viewposX,viewposY,mouse_x,mouse_y);

xTo = viewposX + lengthdir_x(min(200,distance_to_point(mouse_x,mouse_y)),direction);
yTo = viewposY + lengthdir_y(min(200,distance_to_point(mouse_x,mouse_y)),direction);

x += floor((xTo-x)/5);
y += floor((yTo-y)/5);

viewposX = -(vwidth/2) + x;
viewposY = -(vheight/2) + y;

viewposX = clamp(viewposX,0,room_width-vwidth);
viewposY = clamp(viewposY,0,room_height-vheight);

camera_set_view_pos(cam,viewposX,viewposY);
Jumping method (Step method of a different object)
Code:
var cam, vwidth, vheight;

cam = view_get_camera(0);
vwidth = camera_get_view_width(cam);
vheight = camera_get_view_height(cam);

for (var i = 0; i < ds_list_size(global.list_mappoints); i++){
    var j = ds_list_find_value(global.list_mappoints,i);
    if point_in_rectangle(device_mouse_x_to_gui(0),device_mouse_y_to_gui(0),80,75+i*30,540,100+i*30) && mouse_check_button_pressed(mb_left)
    {
        camera_set_view_pos(cam, clamp((variable_instance_get(j,"x")- vwidth/2),0,room_width-vwidth), clamp((variable_instance_get(j,"y")-vheight/2),0,room_height-vheight) );

    }
 
Last edited by a moderator:
Top