-
-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!: Correct coordinate system for a circular viewport (#2174)
- Loading branch information
Showing
23 changed files
with
251 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...lib/src/experimental/follow_behavior.dart → ...src/camera/behaviors/follow_behavior.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
...ib/src/experimental/camera_component.dart → ...lame/lib/src/camera/camera_component.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...lame/lib/src/experimental/viewfinder.dart → ...ages/flame/lib/src/camera/viewfinder.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/flame/lib/src/camera/viewports/circular_viewport.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:flame/src/camera/viewport.dart'; | ||
import 'package:vector_math/vector_math_64.dart'; | ||
|
||
/// A fixed-size viewport in the shape of a circle (or ellipse). | ||
/// | ||
/// This viewport does not adjust its size or position on the screen in response | ||
/// to game resize events. However, the [size] of the viewport can be changed | ||
/// manually at runtime. | ||
class CircularViewport extends Viewport { | ||
CircularViewport(double radius, {super.children}) { | ||
// This will also call [onViewportResize] | ||
size = Vector2.all(2 * radius); | ||
} | ||
|
||
CircularViewport.ellipse(double radiusX, double radiusY, {super.children}) { | ||
size = Vector2(2 * radiusX, 2 * radiusY); | ||
} | ||
|
||
Path _clipPath = Path(); | ||
double _radiusX = 0.0; | ||
double _radiusY = 0.0; | ||
|
||
@override | ||
void clip(Canvas canvas) => canvas.clipPath(_clipPath, doAntiAlias: false); | ||
|
||
@override | ||
bool containsLocalPoint(Vector2 point) { | ||
final fx = point.x / _radiusX - 1; | ||
final fy = point.y / _radiusY - 1; | ||
return fx * fx + fy * fy <= 1; | ||
} | ||
|
||
@override | ||
void onViewportResize() { | ||
_radiusX = size.x / 2; | ||
_radiusY = size.y / 2; | ||
_clipPath = Path()..addOval(Rect.fromLTRB(0, 0, size.x, size.y)); | ||
} | ||
|
||
@override | ||
void renderDebugMode(Canvas canvas) { | ||
canvas.drawPath(_clipPath, debugPaint); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...rimental/fixed_aspect_ratio_viewport.dart → ...iewports/fixed_aspect_ratio_viewport.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...src/experimental/fixed_size_viewport.dart → ...camera/viewports/fixed_size_viewport.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...me/lib/src/experimental/max_viewport.dart → ...ib/src/camera/viewports/max_viewport.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ges/flame/lib/src/experimental/world.dart → packages/flame/lib/src/camera/world.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
packages/flame/lib/src/experimental/circular_viewport.dart
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.