Skip to content

Commit

Permalink
fix(flame): Export FixedResolutionViewport and make `withFixedResol…
Browse files Browse the repository at this point in the history
…ution` a redirect constructor (#2817)

The CameraComponent.withFixedResolution was a factory but can easily be a redirect constructor, allowing developers to use it when they extend the CameraComponent. On top of that the FixedResolutionViewport was not being exported so if a developer wanted to have a custom camera with a FixedResolutionViewport there was no way to do so unless they imported from src/ or copied the code, both are bad practices 😄
  • Loading branch information
wolfenrain committed Oct 15, 2023
1 parent 6626989 commit 3420d0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 2 additions & 0 deletions packages/flame/lib/camera.dart
Expand Up @@ -7,6 +7,8 @@ export 'src/camera/viewport.dart' show Viewport;
export 'src/camera/viewports/circular_viewport.dart' show CircularViewport;
export 'src/camera/viewports/fixed_aspect_ratio_viewport.dart'
show FixedAspectRatioViewport;
export 'src/camera/viewports/fixed_resolution_viewport.dart'
show FixedResolutionViewport;
export 'src/camera/viewports/fixed_size_viewport.dart' show FixedSizeViewport;
export 'src/camera/viewports/max_viewport.dart' show MaxViewport;
export 'src/camera/world.dart' show World;
20 changes: 9 additions & 11 deletions packages/flame/lib/src/camera/camera_component.dart
Expand Up @@ -65,22 +65,20 @@ class CameraComponent extends Component {
/// [height] pixels are visible within the viewport. The viewfinder will be
/// initially set up to show world coordinates (0, 0) at the center of the
/// viewport.
factory CameraComponent.withFixedResolution({
CameraComponent.withFixedResolution({
required double width,
required double height,
Viewfinder? viewfinder,
World? world,
Viewfinder? viewfinder,
Component? backdrop,
List<Component>? hudComponents,
}) {
return CameraComponent(
world: world,
viewport: FixedResolutionViewport(resolution: Vector2(width, height))
..addAll(hudComponents ?? []),
viewfinder: viewfinder ?? Viewfinder(),
backdrop: backdrop,
);
}
}) : this(
world: world,
viewport: FixedResolutionViewport(resolution: Vector2(width, height)),
viewfinder: viewfinder ?? Viewfinder(),
backdrop: backdrop,
hudComponents: hudComponents,
);

/// The [viewport] is the "window" through which the game world is observed.
///
Expand Down

0 comments on commit 3420d0e

Please sign in to comment.