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: CameraComponent no longer throws Concurrent modification on stop #2997

Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion packages/flame/lib/src/camera/camera_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class CameraComponent extends Component {

/// Removes all movement effects or behaviors from the viewfinder.
void stop() {
viewfinder.children.forEach((child) {
viewfinder.children.toList().forEach((child) {
if (child is FollowBehavior || child is MoveEffect) {
child.removeFromParent();
}
Expand Down
13 changes: 13 additions & 0 deletions packages/flame/test/camera/camera_component_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ void main() {
}
});

testWithFlameGame('camera should be able to retarget follow', (game) async {
final world = World()..addToParent(game);
final camera = CameraComponent(world: world)..addToParent(game);
spydon marked this conversation as resolved.
Show resolved Hide resolved
final player = PositionComponent()..addToParent(world);
final player2 = PositionComponent()..addToParent(world);
camera.follow(player);
camera.follow(player2);
await game.ready();

expect(camera.viewfinder.children.length, 1);
expect(camera.viewfinder.children.first, isA<FollowBehavior>());
});

testWithFlameGame('follow with snap', (game) async {
final world = World()..addToParent(game);
final player = PositionComponent()
Expand Down
Loading