`Viewfinder.visibleGameSize` zooms in too far with a `FixedResolutionViewport`
维护者通常 1 天内回复
评估
这个 Issue 还没有评估数据。
描述
What happened?
visibleGameSize sets the zoom so that the given region fits into the viewport. _updateZoom (viewfinder.dart#L201-L208) calculates it from viewport.size, which is the size of the viewport on the screen. The viewfinder works in the viewport's virtualSize though, which for a FixedResolutionViewport is its resolution, and the viewport scales that up to the screen afterwards. So with a FixedResolutionViewport, the scale is applied twice.
With a 320×180 resolution in a 1280×720 window and visibleGameSize = Vector2(330, 228), the zoom is 3.16, and only 101×57 units of the 330×228 room are visible. When the window is resized to 640×360, the zoom changes to 1.58 and 202×114 units are visible, so how much of the world is visible depends on the window size, which is what FixedResolutionViewport is meant to prevent.
The documentation of visibleGameSize (viewfinder.dart#L149-L150) also says that setting it removes any fixed resolution constraints, which isn't true. That is left over from when CameraComponent.withFixedResolution was built from a FixedAspectRatioViewport with visibleGameSize (#2776), where size and virtualSize were the same.
https://github.com/user-attachments/assets/b45609c3-0373-4aee-ab32-30d8e1338f4e
What do you expect?
The zoom is calculated against the resolution, min(320 / 330, 180 / 228) ≈ 0.79, so the whole 330×228 room is visible at any window size.
How can we reproduce this?
- Create a camera with
CameraComponent.withFixedResolution(width: 320, height: 180). - Set
camera.viewfinder.visibleGameSize = Vector2(330, 228). - Run it in a 1280×720 window. The zoom is 3.16 instead of 0.79, and only the center of the room is visible.
What steps should take to fix this?
_updateZoom will use viewport.virtualSize instead of viewport.size, and the documentation of visibleGameSize will say that the region is fitted into the viewport's virtual size, i.e. the resolution of a FixedResolutionViewport.
Do have an example of where the bug occurs?
import 'dart:ui';
import 'package:flame/camera.dart';
import 'package:flame/components.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 {
ReproGame()
: super(
camera: CameraComponent.withFixedResolution(width: 320, height: 180),
);
@override
Future<void> onLoad() async {
// A single-screen room that should always be fully visible.
world.add(
RectangleComponent(
size: Vector2(330, 228),
anchor: Anchor.center,
paint: Paint()..color = Colors.brown,
),
);
camera.viewfinder.visibleGameSize = Vector2(330, 228);
}
}
Expected: the whole room is visible, at any window size. Actual: only the center of the room is visible, and how much of it depends on the window size.
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
Are you interested in working on a PR for this?
- I want to work on this
- 主要语言
- Dart
- 星标
- 10.8k
- 派生
- 1.1k
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 54
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
flame-engine/flame 的其他 Issue
-
Add support to share the polygons of a Path among PathComponent and PathHitbox可能已有人在做 @adario 于 1 天前认领。 未关闭enhancement
难度 4/5 1-2 天 新手友好度 15/100
flame-engine/flame#4217 ·
维护者通常 1 天内回复
-
`UniformsSetter.setColor` sends every color to the shader as black可能已有人在做 @ufrshubham 于 3 天前认领。 未关闭bug
flame-engine/flame#4211 · 已指派 1 人 ·
维护者通常 1 天内回复
-
`Viewfinder.visibleGameSize` is not reapplied when the viewport changes size可能已有人在做 @ufrshubham 于 6 天前认领。 未关闭bug
flame-engine/flame#4204 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Camera bounds with `considerViewport: true` are not updated when the viewport is resized可能已有人在做 @ufrshubham 于 6 天前认领。 未关闭bug
flame-engine/flame#4202 · 已指派 1 人 ·
维护者通常 1 天内回复
-
`CameraComponent.setBounds` with `considerViewport: true` only works for bounds that start at (0, 0), at zoom 1可能已有人在做 @ufrshubham 于 6 天前认领。 未关闭bug
flame-engine/flame#4201 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 flame-engine/flame 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 66/100
bggRGjQaUbCoE/PiliPlus#3522 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 79/100
-
难度 2/5 1-3 小时 新手友好度 79/100
ccch1mneyyy/dsh-Go#731 ·
维护者通常 1 天内回复
-
enhancement good first issue help wanted
难度 2/5 1-3 小时 新手友好度 88/100