1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

How would I prevent my camera from seeing outside the room

Discussion in 'Programming' started by Niften, Aug 31, 2017.

  1. Niften

    Niften Member

    Joined:
    Aug 14, 2016
    Posts:
    226
    How would I prevent my camera from seeing outside the room?
    CREATE
    Code:
    #macro CAMERA_WIDTH 1024
    #macro CAMERA_HEIGHT 768
    
    camera = camera_create();
    
    var vm = matrix_build_lookat(x,y,-10,x,y,0,0,1,0);
    var pm = matrix_build_projection_ortho(CAMERA_WIDTH/3,CAMERA_HEIGHT/3,1,10000);
    
    camera_set_view_mat(camera,vm);
    camera_set_proj_mat(camera,pm);
    
    view_camera[0] = camera;
    
    follow = obj_player;
    xTo = x;
    yTo = y;
    
    game_set_speed(60, gamespeed_fps);
    
    STEP
    Code:
    x += (xTo - x)/10;
    y += (yTo - y)/10;
    
    //x = xTo;
    //y = yTo;
    
    if (follow != noone) {
        xTo = follow.x;
        yTo = follow.y;
    }
    
    var vm = matrix_build_lookat(x,y,-10,x,y,0,0,1,0);
    camera_set_view_mat(camera,vm);
    
     
  2. sitebender

    sitebender Member

    Joined:
    Sep 13, 2016
    Posts:
    840
    Put a clamp on it!

    view_xview = clamp(view_xview, 0, room_width - view_wview)
    view_yview = clamp(view_yview, 0, room_height - view_hview)
     
  3. Niften

    Niften Member

    Joined:
    Aug 14, 2016
    Posts:
    226
    Doesn't work in GameMaker 2, that's why I was asking
     
  4. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    7,046
    Yes it does, as long as you change the view_x/yview array to use the appropriate functions...

    Code:
    var _vx = clamp(camera_get_view_x(view_camera[0]), 0, room_width - camera_get_view_width(view_camera[0]));
    var _vy = clamp(camera_get_view_y(view_camera[0]), 0, room_height - camera_get_view_height(view_camera[0]))
    camera_set_view_pos(view_camera[0], _vx, _vy);
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice