Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Tiled component orthogonal test #2549

Merged
merged 9 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,19 @@
/// position.
/// https://doc.mapeditor.org/en/latest/manual/layers/#parallax-scrolling-factor
void applyParallaxOffset(Canvas canvas, CameraComponent camera) {
final anchor = camera.viewfinder.anchor;

Check warning on line 109 in packages/flame_tiled/lib/src/renderable_layers/renderable_layer.dart

View workflow job for this annotation

GitHub Actions / analyze

The value of the local variable 'anchor' isn't used.

Try removing the variable or using it. See https://dart.dev/diagnostics/unused_local_variable to learn more about this problem.
final cameraX = camera.viewfinder.position.x;
final cameraY = camera.viewfinder.position.y;
final viewportCenterX = camera.viewport.size.x * anchor.x;
final viewportCenterY = camera.viewport.size.y * anchor.y;
final viewportCenterX = camera.viewport.size.x / 2;
final viewportCenterY = camera.viewport.size.y / 2;

if (parent is GroupLayer) {
erickzanardo marked this conversation as resolved.
Show resolved Hide resolved
print(layer.name);

Check notice on line 116 in packages/flame_tiled/lib/src/renderable_layers/renderable_layer.dart

View workflow job for this annotation

GitHub Actions / analyze

Don't invoke 'print' in production code.

Try using a logging framework. See https://dart-lang.github.io/linter/lints/avoid_print.html to learn more about this problem.
print(parallaxX);

Check notice on line 117 in packages/flame_tiled/lib/src/renderable_layers/renderable_layer.dart

View workflow job for this annotation

GitHub Actions / analyze

Don't invoke 'print' in production code.

Try using a logging framework. See https://dart-lang.github.io/linter/lints/avoid_print.html to learn more about this problem.
print(parallaxY);

Check notice on line 118 in packages/flame_tiled/lib/src/renderable_layers/renderable_layer.dart

View workflow job for this annotation

GitHub Actions / analyze

Don't invoke 'print' in production code.

Try using a logging framework. See https://dart-lang.github.io/linter/lints/avoid_print.html to learn more about this problem.
print(viewportCenterX);

Check notice on line 119 in packages/flame_tiled/lib/src/renderable_layers/renderable_layer.dart

View workflow job for this annotation

GitHub Actions / analyze

Don't invoke 'print' in production code.

Try using a logging framework. See https://dart-lang.github.io/linter/lints/avoid_print.html to learn more about this problem.
print(viewportCenterY);

Check notice on line 120 in packages/flame_tiled/lib/src/renderable_layers/renderable_layer.dart

View workflow job for this annotation

GitHub Actions / analyze

Don't invoke 'print' in production code.

Try using a logging framework. See https://dart-lang.github.io/linter/lints/avoid_print.html to learn more about this problem.
}

// Due to how Tiled treats the center of the view as the reference
// point for parallax positioning (see Tiled docs), we need to offset the
Expand Down
10 changes: 6 additions & 4 deletions packages/flame_tiled/test/tiled_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -406,29 +406,31 @@ void main() {

final world = World(children: [component]);
final cameraComponent = CameraComponent(world: world);
cameraComponent.viewfinder.anchor = Anchor.topLeft;

// Need to initialize a game and call `onLoad` and `onGameResize` to
// get the camera and canvas sizes all initialized
final game = FlameGame(children: [world, cameraComponent]);
await game.ready();
cameraComponent.viewfinder.anchor = Anchor.topLeft;
cameraComponent.viewfinder.position = Vector2(150, 20);
cameraComponent.viewport.size = mapSizePx.clone();
game.onGameResize(mapSizePx);
component.onGameResize(mapSizePx);
await component.onLoad();
await game.ready();
});

test('component size', () {
expect(component.tileMap.destTileSize, Vector2(16, 16));
expect(component.size, mapSizePx);
});

// TODO(Erick): Don't skip when it is solved.
test(
'renders',
() async {
final pngData = await renderMapToPng(component);

expect(pngData, matchesGoldenFile('goldens/orthogonal.png'));
},
skip: true,
);
});

Expand Down
Loading