Skip to content

Commit d9c8376

Browse files
committed
Merge pull request godotengine#105825 from Alex-Onceanu/playground
Fix `Camera2D` right and bottom limit to depend on bottom right corner
2 parents f648eea + 1bdf237 commit d9c8376

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

scene/2d/camera_2d.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,17 @@ Transform2D Camera2D::get_camera_transform() {
272272
Rect2 screen_rect(-screen_offset + ret_camera_pos, screen_size * zoom_scale);
273273

274274
if (limit_enabled && (!position_smoothing_enabled || !limit_smoothing_enabled)) {
275+
Point2 bottom_right_corner = Point2(screen_rect.position + 2.0 * (camera_pos - screen_rect.position));
275276
if (screen_rect.position.x < limit[SIDE_LEFT]) {
276277
screen_rect.position.x = limit[SIDE_LEFT];
277278
}
278279

279-
if (screen_rect.position.x + screen_rect.size.x > limit[SIDE_RIGHT]) {
280-
screen_rect.position.x = limit[SIDE_RIGHT] - screen_rect.size.x;
280+
if (bottom_right_corner.x > limit[SIDE_RIGHT]) {
281+
screen_rect.position.x = limit[SIDE_RIGHT] - (bottom_right_corner.x - screen_rect.position.x);
281282
}
282283

283-
if (screen_rect.position.y + screen_rect.size.y > limit[SIDE_BOTTOM]) {
284-
screen_rect.position.y = limit[SIDE_BOTTOM] - screen_rect.size.y;
284+
if (bottom_right_corner.y > limit[SIDE_BOTTOM]) {
285+
screen_rect.position.y = limit[SIDE_BOTTOM] - (bottom_right_corner.y - screen_rect.position.y);
285286
}
286287

287288
if (screen_rect.position.y < limit[SIDE_TOP]) {

0 commit comments

Comments
 (0)