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 all 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
1 change: 1 addition & 0 deletions .github/.cspell/gamedev_dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ raytracing # rendering techniques that calculates light rays as straight lines
rects # plural of rect
respawned # past tense of respawn
respawn # when the player character dies and is brought back after some time and penalties
retarget # to direct (something) toward a different target
RGBA # red green blue alpha
RGBO # red green blue opacity
rrect # rounded rect
Expand Down
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
14 changes: 14 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,20 @@ void main() {
}
});

testWithFlameGame('camera should be able to retarget follow', (game) async {
// Creating new camera as the one included with game is not mounted and
// will therefore not be queued.
final camera = CameraComponent(world: game.world)..addToParent(game);
final player = PositionComponent()..addToParent(game.world);
final player2 = PositionComponent()..addToParent(game.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