Skip to content

Commit

Permalink
Add golden tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spydon committed Oct 5, 2023
1 parent b288b5b commit 47baf20
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/flame/camera_component.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ you want to have a static `ParallaxComponent` beneath a world that you can move
around it.

Example:

```dart
camera.backdrop.add(MyStaticBackground());
```
Expand Down
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.
83 changes: 83 additions & 0 deletions packages/flame/test/camera/camera_component_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,89 @@ void main() {
);
});

testGolden(
'Correct scale of rendering',
(game) async {
final world = World();
final resolution = Vector2(40, 60);
final camera = CameraComponent.withFixedResolution(
world: world,
width: resolution.x,
height: resolution.y,
);
game.addAll([world, camera]);
camera.viewfinder.position = Vector2.all(4);
camera.backdrop.add(
CrossHair(
size: Vector2.all(28),
position: resolution / 2 + Vector2.all(4),
color: Colors.teal,
),
);
camera.viewfinder.add(
CrossHair(
size: Vector2.all(20),
position: resolution / 2 + Vector2(-6, 0),
color: Colors.white,
),
);
world.add(
CrossHair(size: Vector2.all(14), color: Colors.green),
);
camera.viewport.add(
CrossHair(
size: Vector2.all(8),
position: resolution / 2 + Vector2(4, -4),
color: Colors.red,
),
);
},
goldenFile: '../_goldens/camera_component_prescale_test.png',
size: Vector2(50, 50),
);

testGolden(
'Correct scale of rendering after zoom',
(game) async {
final world = World();
final resolution = Vector2(40, 60);
final camera = CameraComponent.withFixedResolution(
world: world,
width: resolution.x,
height: resolution.y,
);
game.addAll([world, camera]);
camera.viewfinder.position = Vector2.all(4);
camera.viewfinder.zoom = 1.5;
camera.backdrop.add(
CrossHair(
size: Vector2.all(28),
position: resolution / 2 + Vector2.all(4),
color: Colors.teal,
),
);
camera.viewfinder.add(
CrossHair(
size: Vector2.all(20),
position: resolution / 2 + Vector2(-6, 0),
color: Colors.white,
),
);
world.add(
CrossHair(size: Vector2.all(14), color: Colors.green),
);
camera.viewport.add(
CrossHair(
size: Vector2.all(8),
position: resolution / 2 + Vector2(4, -4),
color: Colors.red,
),
);
},
goldenFile: '../_goldens/camera_component_prescale_zoom_test.png',
size: Vector2(50, 50),
);

group('CameraComponent.canSee', () {
testWithFlameGame('null world', (game) async {
final player = PositionComponent();
Expand Down

0 comments on commit 47baf20

Please sign in to comment.