diff --git a/packages/flame/lib/src/camera/viewfinder.dart b/packages/flame/lib/src/camera/viewfinder.dart index cf7dc1db891..33563c73a01 100644 --- a/packages/flame/lib/src/camera/viewfinder.dart +++ b/packages/flame/lib/src/camera/viewfinder.dart @@ -1,9 +1,7 @@ import 'dart:math'; +import 'package:flame/components.dart'; import 'package:flame/extensions.dart'; -import 'package:flame/src/anchor.dart'; -import 'package:flame/src/camera/camera_component.dart'; -import 'package:flame/src/components/core/component.dart'; import 'package:flame/src/effects/provider_interfaces.dart'; import 'package:flame/src/game/transform2d.dart'; import 'package:meta/meta.dart'; @@ -18,7 +16,12 @@ import 'package:meta/meta.dart'; /// If you add children to the [Viewfinder] they will appear like HUDs i.e. /// statically in front of the world. class Viewfinder extends Component - implements AnchorProvider, AngleProvider, PositionProvider, ScaleProvider { + implements + AnchorProvider, + AngleProvider, + PositionProvider, + ScaleProvider, + CoordinateTransform { /// Transform matrix used by the viewfinder. final Transform2D transform = Transform2D(); @@ -180,6 +183,16 @@ class Viewfinder extends Component } } + @override + Vector2 parentToLocal(Vector2 point) { + return globalToLocal(point); + } + + @override + Vector2 localToParent(Vector2 point) { + return localToGlobal(point); + } + @override void onGameResize(Vector2 size) { _updateZoom(); diff --git a/packages/flame/lib/src/camera/viewport.dart b/packages/flame/lib/src/camera/viewport.dart index da1fb48feee..96d89a23be0 100644 --- a/packages/flame/lib/src/camera/viewport.dart +++ b/packages/flame/lib/src/camera/viewport.dart @@ -1,9 +1,7 @@ +import 'package:flame/components.dart'; import 'package:flame/extensions.dart'; import 'package:flame/game.dart'; -import 'package:flame/src/anchor.dart'; -import 'package:flame/src/camera/camera_component.dart'; import 'package:flame/src/camera/viewports/fixed_resolution_viewport.dart'; -import 'package:flame/src/components/core/component.dart'; import 'package:flame/src/effects/provider_interfaces.dart'; import 'package:meta/meta.dart'; @@ -21,7 +19,11 @@ import 'package:meta/meta.dart'; /// A viewport establishes its own local coordinate system, with the origin at /// the top left corner of the viewport's bounding box. abstract class Viewport extends Component - implements AnchorProvider, PositionProvider, SizeProvider { + implements + AnchorProvider, + PositionProvider, + SizeProvider, + CoordinateTransform { Viewport({super.children}); final Vector2 _size = Vector2.zero(); @@ -148,6 +150,16 @@ abstract class Viewport extends Component return (output?..setValues(x, y)) ?? Vector2(x, y); } + @override + Vector2 parentToLocal(Vector2 point) { + return globalToLocal(point); + } + + @override + Vector2 localToParent(Vector2 point) { + return localToGlobal(point); + } + void transformCanvas(Canvas canvas) { canvas.transform2D(transform); }