CameraComponent.withFixedResolution constructor

CameraComponent.withFixedResolution({
  1. required double width,
  2. required double height,
  3. World? world,
  4. Viewfinder? viewfinder,
  5. Component? backdrop,
  6. List<Component>? hudComponents,
})

Create a camera that shows a portion of the game world of fixed size width x height.

The viewport will be centered within the canvas, expanding as much as possible on all sides while maintaining the width:height aspect ratio. The zoom level will be set such in such a way that exactly width x 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.

Implementation

CameraComponent.withFixedResolution({
  required double width,
  required double height,
  World? world,
  Viewfinder? viewfinder,
  Component? backdrop,
  List<Component>? hudComponents,
}) : this(
        world: world,
        viewport: FixedResolutionViewport(resolution: Vector2(width, height)),
        viewfinder: viewfinder ?? Viewfinder(),
        backdrop: backdrop,
        hudComponents: hudComponents,
      );