Skip to content

Commit

Permalink
fix: renderChain should allow open-ended chain drawing (#1804)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeb-dev committed Jul 18, 2022
1 parent e53b633 commit 60daa19
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
3 changes: 1 addition & 2 deletions packages/flame_forge2d/lib/body_component.dart
Expand Up @@ -125,8 +125,7 @@ abstract class BodyComponent<T extends Forge2DGame> extends Component
}

void renderChain(Canvas canvas, List<Offset> points) {
final path = Path()..addPolygon(points, true);
canvas.drawPath(path, paint);
canvas.drawPoints(PointMode.polygon, points, paint);
}

void _renderCircle(Canvas canvas, Fixture fixture) {
Expand Down
33 changes: 31 additions & 2 deletions packages/flame_forge2d/test/body_component_test.dart
Expand Up @@ -117,7 +117,7 @@ void main() {
);

flameTester.testGameWidget(
'a ChainShape',
'an open ChainShape',
setUp: (game, tester) async {
final body = game.world.createBody(BodyDef());
final shape = ChainShape()
Expand All @@ -140,7 +140,36 @@ void main() {
verify: (game, tester) async {
await expectLater(
find.byGame<Forge2DGame>(),
matchesGoldenFile(goldenPath('chain_shape')),
matchesGoldenFile(goldenPath('chain_shape_open')),
);
},
);

flameTester.testGameWidget(
'a closed ChainShape',
setUp: (game, tester) async {
final body = game.world.createBody(BodyDef());
final shape = ChainShape()
..createLoop(
[
Vector2.zero(),
Vector2.all(10),
Vector2(10, 0),
],
);
body.createFixture(FixtureDef(shape));

final component = _TestBodyComponent()
..body = body
..paint = testPaint;
await game.add(component);

game.camera.followVector2(Vector2.zero());
},
verify: (game, tester) async {
await expectLater(
find.byGame<Forge2DGame>(),
matchesGoldenFile(goldenPath('chain_shape_closed')),
);
},
);
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 60daa19

Please sign in to comment.