Didjynn
Member
Hello everyone,
I have a viewport zooming in and out.
The thing is (and I don't find why that's why I'm here), zooming in or out teleports the center of my view to the bottom right corner of the room. Always. And I have absolutly no idea why.
Tell me if I mistake but the position of the view is the middle of it (I checked) and not the top left corner.
To avoid the view to show what's outside of the room, I check the position
(for the right side) when to divide camera_get_view_width(view_camera[0]) by 2 seemed much more logical to me.
For the zoom itself here is my code, there is some lines but nothing complicated (or maybe it is since I can't debug it )
Now is the code for my zooming system, as I said I don't get why the center of the viewport when I zoom in and out go in the bottom right corner of the room. If somebody can help me ?
This is the script I have in the 2 conditions to clean the code :
I have a viewport zooming in and out.
The thing is (and I don't find why that's why I'm here), zooming in or out teleports the center of my view to the bottom right corner of the room. Always. And I have absolutly no idea why.
Tell me if I mistake but the position of the view is the middle of it (I checked) and not the top left corner.
To avoid the view to show what's outside of the room, I check the position
Code:
room_width - camera_get_view_width(view_camera[0])
For the zoom itself here is my code, there is some lines but nothing complicated (or maybe it is since I can't debug it )
Now is the code for my zooming system, as I said I don't get why the center of the viewport when I zoom in and out go in the bottom right corner of the room. If somebody can help me ?
Code:
// ZOOM
if mouse_wheel_down() {
if zoom_factor < 1 {
zoom_factor += 0.1
camera_set_view_size(view_camera[0], room_width * zoom_factor, room_height * zoom_factor)
cam_width = camera_get_view_width(view_camera[0]) / 2
cam_height = camera_get_view_height(view_camera[0]) / 2
show_debug_message("mx = " + string(mouse_x) + " my = " + string(mouse_y))
camera_set_view_pos(view_camera[0], mouse_x, mouse_y);
show_debug_message("viewport x = " + string(camera_get_view_x(view_camera[0])) + " y = " + string(camera_get_view_y(view_camera[0])))
scrCamPos()
}
}else if mouse_wheel_up(){
if zoom_factor > 0.1 {
zoom_factor -= 0.1
camera_set_view_size(view_camera[0], room_width * zoom_factor, room_height * zoom_factor)
cam_width = camera_get_view_width(view_camera[0]) / 2
cam_height = camera_get_view_height(view_camera[0]) / 2
camera_set_view_pos(view_camera[0], mouse_x, mouse_y);
scrCamPos()
}
}
Code:
//scrCamPos
if camera_get_view_x(view_camera[0]) + cam_width > room_width {
camera_set_view_pos(view_camera[0], room_width - cam_width, camera_get_view_y(view_camera[0]))
show_debug_message("post zoom viewport x = " + string(camera_get_view_x(view_camera[0])) + " y = " + string(camera_get_view_y(view_camera[0])))
window_mouse_set(window_get_width() / 2, window_get_height() / 2)
}
if camera_get_view_x(view_camera[0]) - cam_width < 0 {
camera_set_view_pos(view_camera[0], cam_width, camera_get_view_y(view_camera[0]))
show_debug_message("post zoom viewport x = " + string(camera_get_view_x(view_camera[0])) + " y = " + string(camera_get_view_y(view_camera[0])))
window_mouse_set(window_get_width() / 2, window_get_height() / 2)
}
if camera_get_view_y(view_camera[0]) - cam_height < 0 {
camera_set_view_pos(view_camera[0], camera_get_view_x(view_camera[0]), cam_height)
show_debug_message("post zoom viewport x = " + string(camera_get_view_x(view_camera[0])) + " y = " + string(camera_get_view_y(view_camera[0])))
window_mouse_set(window_get_width() / 2, window_get_height() / 2)
}
if camera_get_view_y(view_camera[0]) + cam_height > room_height {
camera_set_view_pos(view_camera[0], camera_get_view_x(view_camera[0]), room_height - cam_height)
show_debug_message("post zoom viewport x = " + string(camera_get_view_x(view_camera[0])) + " y = " + string(camera_get_view_y(view_camera[0])))
window_mouse_set(window_get_width() / 2, window_get_height() / 2)
}