diff --git a/CHANGELOG.md b/CHANGELOG.md index 9705abfb4..a9cb2d0aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # CHANGELOG ## [next] - - Adding BaseGame#remove + - Adding BaseGame#markToRemove - Upgrade tiled and flutter_svg dependencies ## 0.22.1 diff --git a/doc/game.md b/doc/game.md index 86ce970fe..a1097bca4 100644 --- a/doc/game.md +++ b/doc/game.md @@ -45,7 +45,7 @@ A very simple `BaseGame` implementation example can be seen below: } ``` -To remove components from the list on a `BaseGame` the `remove` can be used. +To remove components from the list on a `BaseGame` the `markToRemove` method can be used. ## Flutter Widgets and Game instances diff --git a/example/lib/main.dart b/example/lib/main.dart index ec4a7a710..fa70e444b 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -69,7 +69,7 @@ class MyGame extends BaseGame with DoubleTapDetector, TapDetector { components.forEach((c) { if (c is PositionComponent && c.toRect().overlaps(touchArea)) { handled = true; - remove(c); + markToRemove(c); } }); diff --git a/lib/components/composed_component.dart b/lib/components/composed_component.dart index 74109923f..e536c2c0f 100644 --- a/lib/components/composed_component.dart +++ b/lib/components/composed_component.dart @@ -75,7 +75,7 @@ mixin ComposedComponent on Component, HasGameRef, Tapable { components.add(c); } - void remove(Component component) { + void markToRemove(Component component) { _removeLater.add(component); } diff --git a/lib/game/base_game.dart b/lib/game/base_game.dart index 86e020a73..c8246a7e9 100644 --- a/lib/game/base_game.dart +++ b/lib/game/base_game.dart @@ -89,8 +89,8 @@ class BaseGame extends Game { _addLater.add(c); } - /// Removes a component from the components list - void remove(Component c) { + /// Marks a component to be removed from the components list on the next game loop cycle + void markToRemove(Component c) { _removeLater.add(c); }