Camera bounds with `considerViewport: true` are not updated when the viewport is resized
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
What happened?
With camera.setBounds(bounds, considerViewport: true), the region that the camera has to stay in depends on the size of the viewport. ViewportAwareBoundsBehavior only recalculates it when the scale of the viewfinder or of the viewport's transform changes (viewport_aware_bounds_behavior.dart#L26-L30). MaxViewport and FixedAspectRatioViewport change their size, not their scale, when the window is resized, so the bounds keep using the size that the viewport had when setBounds was called. After the window is made bigger, the camera shows the empty space past the edges of the bounds. After it is made smaller, the edges can't be reached anymore.
Since the behavior listens to the viewport's transform directly, it also keeps listening to the old viewport after camera.viewport is replaced, and onRemove then removes the listener from the new viewport instead.
https://github.com/user-attachments/assets/1d7a89c2-d8de-4430-8cb6-42ca099c0e79
What do you expect?
The bounds are recalculated whenever the size of the viewport changes, so the camera never shows past the bounds, at any window size.
How can we reproduce this?
- With the default
MaxViewportand an 800×600 window, callcamera.setBounds(Rectangle.fromLTWH(0, 0, 1500, 900), considerViewport: true). - Move the camera to the top-left corner. It stops at (400, 300), with the corner of the bounds at the corner of the screen.
- Resize the window to 1280×720. The camera stays at (400, 300) instead of (640, 360), and the left 240 and top 60 units of the screen show the empty space outside of the bounds.
What steps should take to fix this?
The viewport already notifies the viewfinder when its size changes, through Viewfinder.onViewportResize (viewport.dart#L88). The viewfinder will pass that on to its ViewportAwareBoundsBehavior, which recalculates the bounds whenever the size of the visible world region has changed. For zoom and angle changes, the behavior will listen to the viewfinder's transform instead of the viewport's transform, which also gets rid of the stale listener when the viewport is replaced.
Do have an example of where the bug occurs?
import 'dart:ui';
import 'package:flame/components.dart';
import 'package:flame/experimental.dart';
import 'package:flame/game.dart';
import 'package:flutter/material.dart' show Colors;
import 'package:flutter/widgets.dart';
void main() => runApp(GameWidget(game: ReproGame()));
class ReproGame extends FlameGame {
@override
Future<void> onLoad() async {
world.add(
RectangleComponent(
size: Vector2(1500, 900),
paint: Paint()..color = Colors.brown,
),
);
camera.setBounds(
Rectangle.fromLTWH(0, 0, 1500, 900),
considerViewport: true,
);
// Look at the top-left corner of the level, then make the window bigger.
camera.moveTo(Vector2(-10000, -10000));
}
}
Run it on desktop or web and make the window bigger. Expected: the corner of the level stays at the corner of the screen. Actual: empty space shows up on the left and at the top.
Relevant log output
Nothing is logged or thrown.
Execute in a terminal and put output into the code block below
[√] Flutter (Channel stable, 3.47.9, on Microsoft Windows [Version 10.0.22631.6199], locale en-US)
• Flutter version 3.47.9 on channel stable
• Framework revision c197ca5199 (4 days ago), 2026-10-29 10:10:20 -0400
• Engine revision 89c39edfdf
• Dart version 3.13.7
• DevTools version 2.60.0
[√] Windows Version (11 Pro 64-bit, 23H2, 2009)
[√] Android toolchain - develop for Android devices (Android SDK version 36.1.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2026 18.11.2)
[√] Connected device (3 available)
[√] Network resources
• No issues found!
Affected platforms
All
Other information
The fix builds on #4201, which changes how the bounds are calculated.
Are you interested in working on a PR for this?
- I want to work on this
- Ngôn ngữ chính
- Dart
- Star
- 10.8k
- Fork
- 1.1k
- Merge trung bình
- 1 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 54
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của flame-engine/flame
-
`UniformsSetter.setColor` sends every color to the shader as blackCó thể đã có người làm @ufrshubham đã nhận 1 ngày trước. Đang mởbug
flame-engine/flame#4211 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`Viewfinder.visibleGameSize` is not reapplied when the viewport changes sizeCó thể đã có người làm @ufrshubham đã nhận 3 ngày trước. Đang mởbug
flame-engine/flame#4204 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`Viewfinder.visibleGameSize` zooms in too far with a `FixedResolutionViewport`Có thể đã có người làm @ufrshubham đã nhận 3 ngày trước. Đang mởbug
flame-engine/flame#4203 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`CameraComponent.setBounds` with `considerViewport: true` only works for bounds that start at (0, 0), at zoom 1Có thể đã có người làm @ufrshubham đã nhận 3 ngày trước. Đang mởbug
flame-engine/flame#4201 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`findPostProcessFromContext` returns `null` for components rendered with `CameraComponent.postProcess`Có thể đã có người làm @ufrshubham đã nhận 3 ngày trước. Đang mởbug
flame-engine/flame#4200 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của flame-engine/flame
Issue tương tự
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
patarapolw/lingua_srs#103 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Feature]Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 5 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
desktop linux photos
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
lichess-org/mobile#3944 ·
Maintainer thường phản hồi trong vòng 2 ngày