`Viewfinder.visibleGameSize` zooms in too far with a `FixedResolutionViewport`
Los mantenedores suelen responder en 1 día
Evaluación
Este issue todavía no se ha evaluado.
Descripción
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
- Lenguaje dominante
- Dart
- Estrellas
- 10.8k
- Forks
- 1.1k
- Merge medio
- 1 d 21 h
- PR fusionados (30 d)
- 62
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de flame-engine/flame
-
`Viewfinder.visibleGameSize` is not reapplied when the viewport changes sizePosiblemente ocupada @ufrshubham la tomó hace 1 día. Abiertobug
flame-engine/flame#4204 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Camera bounds with `considerViewport: true` are not updated when the viewport is resizedPosiblemente ocupada @ufrshubham la tomó hace 1 día. Abiertobug
flame-engine/flame#4202 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
`CameraComponent.setBounds` with `considerViewport: true` only works for bounds that start at (0, 0), at zoom 1Posiblemente ocupada @ufrshubham la tomó hace 1 día. Abiertobug
flame-engine/flame#4201 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
`findPostProcessFromContext` returns `null` for components rendered with `CameraComponent.postProcess`Posiblemente ocupada @ufrshubham la tomó hace 1 día. Abiertobug
flame-engine/flame#4200 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
`ComponentPool` returns components to the pool while they are still in use, and loses components removed before mountingPosiblemente ocupada @ufrshubham la tomó hace 2 días. Abiertobug
flame-engine/flame#4191 · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de flame-engine/flame
Issues similares
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
InlitX/GymMane#311 · 1 reacción ·
Los mantenedores suelen responder en 4 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
zjs81/meshcore-open#634 ·
Los mantenedores suelen responder en 1 día
-
Flutter: _configureLogging passes a log level to rac_configure_logging, which expects an environmentAbiertobinding:flutter bug p2
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
RunanywhereAI/runanywhere-sdks#1246 ·
Los mantenedores suelen responder en 1 día
-
Remove Info buttonAbiertoenhancement user request
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
mill-road-winter-fair/mill_road_winter_fair_app#646 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
[Bug] 悬浮宠物在 App 外、任务进行中也会变淡并停止动画Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
ccch1mneyyy/dsh-Go#426 ·
Los mantenedores suelen responder en 1 día