Skip to content

Commit

Permalink
Now listening to viewport transformations in order to recalculate the…
Browse files Browse the repository at this point in the history
… camera bounds.
  • Loading branch information
Skyost committed Oct 18, 2023
1 parent ba31084 commit 3f5329a
Showing 1 changed file with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,20 @@ import 'package:flame/src/experimental/geometry/shapes/shape.dart';
/// shapes.
class ViewportAwareBoundsBehavior extends Component with ParentIsA<Viewfinder> {
Shape _originalBounds;
late Rect _visibleWorldRect;

ViewportAwareBoundsBehavior({
required Shape originalBounds,
}) : _originalBounds = originalBounds;

@override
void onLoad() {
_visibleWorldRect = parent.visibleWorldRect;
parent.transform.addListener(_updateCameraBounds);
_updateCameraBounds();
}

@override
void update(double dt) {
if (_visibleWorldRect != parent.visibleWorldRect) {
_visibleWorldRect = parent.visibleWorldRect;
_updateCameraBounds();
}
void onRemove() {
parent.transform.removeListener(_updateCameraBounds);
}

/// Returns the bounds that do not take the viewport into account.
Expand Down

0 comments on commit 3f5329a

Please sign in to comment.