fix: renderChain should allow open-ended chain drawing (#1804)

This commit is contained in:
Ahmet Enes Bayraktar
2022-07-18 22:36:36 +03:00
committed by GitHub
parent e53b6337b9
commit 60daa196a8
4 changed files with 32 additions and 4 deletions

View File

@ -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) {

View File

@ -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()
@ -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')),
);
},
);

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB