From 100886704f3af1a39876fce026b7b9c48e333e3c Mon Sep 17 00:00:00 2001 From: lohnn Date: Mon, 22 Jan 2024 21:22:40 +0100 Subject: [PATCH 1/5] Copy children list before iterating and removing children to avoid `Concurrent modification during iteration` --- packages/flame/lib/src/camera/camera_component.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flame/lib/src/camera/camera_component.dart b/packages/flame/lib/src/camera/camera_component.dart index 76f63a657f9..a75dbaf9d23 100644 --- a/packages/flame/lib/src/camera/camera_component.dart +++ b/packages/flame/lib/src/camera/camera_component.dart @@ -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(); } From 9f1516d0605525b60f2dfda830eeb47a83e897ce Mon Sep 17 00:00:00 2001 From: lohnn Date: Tue, 23 Jan 2024 09:12:36 +0100 Subject: [PATCH 2/5] Added a small test to not break when trying to retarget follow for camera --- .../flame/test/camera/camera_component_test.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/flame/test/camera/camera_component_test.dart b/packages/flame/test/camera/camera_component_test.dart index 2694a3b6ec4..1a229e9271a 100644 --- a/packages/flame/test/camera/camera_component_test.dart +++ b/packages/flame/test/camera/camera_component_test.dart @@ -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); + 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()); + }); + testWithFlameGame('follow with snap', (game) async { final world = World()..addToParent(game); final player = PositionComponent() From b63707ba7021faba15de434a4a67acf3615d3c60 Mon Sep 17 00:00:00 2001 From: lohnn Date: Tue, 23 Jan 2024 09:41:10 +0100 Subject: [PATCH 3/5] Added a small comment and updated test to use world from game in test --- packages/flame/test/camera/camera_component_test.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/flame/test/camera/camera_component_test.dart b/packages/flame/test/camera/camera_component_test.dart index 1a229e9271a..efbdbbfd040 100644 --- a/packages/flame/test/camera/camera_component_test.dart +++ b/packages/flame/test/camera/camera_component_test.dart @@ -61,10 +61,11 @@ void main() { }); testWithFlameGame('camera should be able to retarget follow', (game) async { - final world = World()..addToParent(game); - final camera = CameraComponent(world: world)..addToParent(game); - final player = PositionComponent()..addToParent(world); - final player2 = PositionComponent()..addToParent(world); + // 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(); From 98650bc79e71b7ff47554a955fbd01005af3fc9e Mon Sep 17 00:00:00 2001 From: lohnn Date: Tue, 23 Jan 2024 09:46:33 +0100 Subject: [PATCH 4/5] Added the word retarget to the dictionary --- .github/.cspell/gamedev_dictionary.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/.cspell/gamedev_dictionary.txt b/.github/.cspell/gamedev_dictionary.txt index 642d8737ef9..9bc65aa4679 100644 --- a/.github/.cspell/gamedev_dictionary.txt +++ b/.github/.cspell/gamedev_dictionary.txt @@ -67,3 +67,4 @@ vsync # vertical sync; a graphics technology that synchronizes the software's fr WASD # movement keys on a keyboard WBMP # wireless bitmap image format WebP # WebP image format +retarget # to direct (something) toward a different target From 94c3e9db1293cea528d305388a9fd1258e9d35da Mon Sep 17 00:00:00 2001 From: lohnn Date: Tue, 23 Jan 2024 09:48:07 +0100 Subject: [PATCH 5/5] Moved word in dictionary to adhere to alphabetical ordering --- .github/.cspell/gamedev_dictionary.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/.cspell/gamedev_dictionary.txt b/.github/.cspell/gamedev_dictionary.txt index 9bc65aa4679..df93f810d8d 100644 --- a/.github/.cspell/gamedev_dictionary.txt +++ b/.github/.cspell/gamedev_dictionary.txt @@ -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 @@ -67,4 +68,3 @@ vsync # vertical sync; a graphics technology that synchronizes the software's fr WASD # movement keys on a keyboard WBMP # wireless bitmap image format WebP # WebP image format -retarget # to direct (something) toward a different target