Fix Camera2D right and bottom limit to depend on bottom right corner

This commit is contained in:
Alex Onceanu 2025-04-27 15:19:51 +02:00 committed by Rémi Verschelde
parent e37c6261ea
commit 1bdf237558
No known key found for this signature in database
GPG key ID: C3336907360768E1

View file

@ -272,16 +272,17 @@ Transform2D Camera2D::get_camera_transform() {
Rect2 screen_rect(-screen_offset + ret_camera_pos, screen_size * zoom_scale);
if (limit_enabled && (!position_smoothing_enabled || !limit_smoothing_enabled)) {
Point2 bottom_right_corner = Point2(screen_rect.position + 2.0 * (camera_pos - screen_rect.position));
if (screen_rect.position.x < limit[SIDE_LEFT]) {
screen_rect.position.x = limit[SIDE_LEFT];
}
if (screen_rect.position.x + screen_rect.size.x > limit[SIDE_RIGHT]) {
screen_rect.position.x = limit[SIDE_RIGHT] - screen_rect.size.x;
if (bottom_right_corner.x > limit[SIDE_RIGHT]) {
screen_rect.position.x = limit[SIDE_RIGHT] - (bottom_right_corner.x - screen_rect.position.x);
}
if (screen_rect.position.y + screen_rect.size.y > limit[SIDE_BOTTOM]) {
screen_rect.position.y = limit[SIDE_BOTTOM] - screen_rect.size.y;
if (bottom_right_corner.y > limit[SIDE_BOTTOM]) {
screen_rect.position.y = limit[SIDE_BOTTOM] - (bottom_right_corner.y - screen_rect.position.y);
}
if (screen_rect.position.y < limit[SIDE_TOP]) {