Blossomforth

camera object step

Jul 16th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Update camera coordinates.
  2. if keyboard_check(ord('A')) x -= pan_speed;
  3. if keyboard_check(ord('D')) x += pan_speed;
  4. if keyboard_check(ord('W')) y -= pan_speed;
  5. if keyboard_check(ord('S')) y += pan_speed;
  6.  
  7. //Update camera scale, correct out of bounds zoom scales,
  8. //and handle directional camera movement
  9. if mouse_wheel_down() or mouse_wheel_up() {
  10.     if mouse_wheel_down() zoom_scale += zoom_tick;
  11.     if mouse_wheel_up() zoom_scale -= zoom_tick;
  12.     if zoom_scale > zoom_scale_max zoom_scale = zoom_scale_max;
  13.     if zoom_scale < zoom_scale_min zoom_scale = zoom_scale_min;
  14.    
  15.     //Okay to us zoom_scale now. zoom_scale has been updated.
  16.    
  17.     //Ratio of mouse coordinates on window to dimensions of window.
  18.     var x_ratio = window_mouse_get_x() / window_get_width();
  19.     var y_ratio = window_mouse_get_y() / window_get_height();
  20.    
  21.     //Projected new view dimensions
  22.     var new_width = room_width * zoom_scale;
  23.     var new_height = room_height * zoom_scale;
  24.    
  25.     //Set coordinates
  26.     x = mouse_x - (new_width * x_ratio) + (new_width / 2);
  27.     y = mouse_y - (new_height * y_ratio) + (new_height / 2);
  28. }
  29.  
  30. //finalize camera coordinates before here
  31.  
  32. //Check out of bounds for camera object.
  33. if x > room_width x = room_width;
  34. else if x < 0 x = 0;
  35. if y > room_height y = room_height;
  36. else if y < 0 y = 0;
  37.  
  38. //Update _wview and _hview to scale
  39. view_wview[0] = room_width * zoom_scale;
  40. view_hview[0] = room_height * zoom_scale;
  41.  
  42. //finalize _wview and _hview before here
  43.  
  44. //Update camera coordinates.
  45. view_xview[0] = x - view_wview[0] / 2;
  46. view_yview[0] = y - view_hview[0] / 2;
  47. if view_xview[0] < 0 view_xview[0] = 0;
  48. if view_xview[0] + view_wview[0] > room_width view_xview[0] = room_width - view_wview[0];
  49. if view_yview[0] < 0 view_yview[0] = 0;
  50. if view_yview[0] + view_hview[0] > room_height view_yview[0] = room_height - view_hview[0];
Advertisement