Camera bounds with `considerViewport: true` are not updated when the viewport is resized
メンテナーはふだん 1 日以内に返信
評価
この issue はまだ評価されていません。
説明
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
- 主要言語
- Dart
- スター
- 10.8k
- フォーク
- 1.1k
- 平均マージ
- 1日 21時間
- マージ済み PR(30日)
- 62
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
flame-engine/flame のほかの issue
-
`Viewfinder.visibleGameSize` is not reapplied when the viewport changes size対応中かも @ufrshubham が 1 日前に担当しました。 オープンbug
flame-engine/flame#4204 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
`Viewfinder.visibleGameSize` zooms in too far with a `FixedResolutionViewport`対応中かも @ufrshubham が 1 日前に担当しました。 オープンbug
flame-engine/flame#4203 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
`CameraComponent.setBounds` with `considerViewport: true` only works for bounds that start at (0, 0), at zoom 1対応中かも @ufrshubham が 1 日前に担当しました。 オープンbug
flame-engine/flame#4201 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
`findPostProcessFromContext` returns `null` for components rendered with `CameraComponent.postProcess`対応中かも @ufrshubham が 1 日前に担当しました。 オープンbug
flame-engine/flame#4200 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
`ComponentPool` returns components to the pool while they are still in use, and loses components removed before mounting対応中かも @ufrshubham が 2 日前に担当しました。 オープンbug
flame-engine/flame#4191 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
flame-engine/flame の issue をすべて見る
似ている issue
-
check-relative-paths reports links to existing directories as missing対応中かも @reidbaker-agent が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
google/skills_lint.dart#202 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
InlitX/GymMane#311 · リアクション 1 件 ·
メンテナーはふだん 4 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
zjs81/meshcore-open#634 ·
メンテナーはふだん 1 日以内に返信