diff --git a/lib/box2d/box2d_component.dart b/lib/box2d/box2d_component.dart index 428f4e88b95..af455c57fc3 100644 --- a/lib/box2d/box2d_component.dart +++ b/lib/box2d/box2d_component.dart @@ -17,7 +17,7 @@ abstract class Box2DComponent extends Component { int positionIterations; World world; - List components = []; + List components = []; Viewport viewport; Box2DComponent({ @@ -51,7 +51,9 @@ abstract class Box2DComponent extends Component { return; } components.forEach((c) { - c.render(canvas); + if (c.body.isActive()) { + c.render(canvas); + } }); } @@ -63,14 +65,19 @@ abstract class Box2DComponent extends Component { }); } - void add(Component component) { + void add(BodyComponent component) { components.add(component); } - void addAll(List component) { + void addAll(List component) { components.addAll(component); } + void remove(BodyComponent component) { + components.remove(component); + world.destroyBody(component.body); + } + void initializeWorld(); void cameraFollow(