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

feat!: Move Forge2DGame to use CameraComponent #2728

Merged
merged 33 commits into from Sep 16, 2023

Conversation

spydon
Copy link
Member

@spydon spydon commented Sep 11, 2023

Description

This enables flame_forge2d to work with the CameraComponent and the new event system.

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.

Migration instructions

  • Add all your components to Forge2DGame.world instead of directly to the root of the game.
  • Get all your camera values from Forge2DGame.cameraComponent instead of from Forge2DGame.camera.

Related Issues

Closes #2547
Closes #2606
Closes #2587
Closes #2491

@spydon spydon marked this pull request as ready for review September 11, 2023 18:07
@@ -102,15 +102,15 @@ class Car extends BodyComponent<PadRacingGame> {
final isLeftTire = i.isEven;
return Tire(
car: this,
pressedKeys: gameRef.pressedKeySets[playerNumber],
pressedKeys: game.pressedKeySets[playerNumber],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the rename from gameRef to game?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is from the really old Pasha PR where we are moving from the HasGameRef mixin to HasGameReference.

@@ -58,13 +57,13 @@ class PadRacingGame extends Forge2DGame with KeyboardEvents {

@override
Future<void> onLoad() async {
super.onLoad();
cameraComponent.removeFromParent();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine this is because it gets re-added later and you want to call onLoad to reset the game? just curious what breaks if you just leave the camera there as is?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This camera isn't used, it uses several other cameras later instead.


final Vector2 position;
final Vector2 _position;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine things like this and initialPosition are to avoid conflict with a position defined on BodyComponent.
but why can't we just use that position for everything? where do components need to keep a separate track of a second position?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because position is a read-only on BodyComponent since it is a getter from the Body.

@spydon spydon enabled auto-merge (squash) September 16, 2023 08:01
@spydon spydon merged commit 7a3d512 into main Sep 16, 2023
7 checks passed
@spydon spydon deleted the spydon/move-forge2d-to-cameracomponent branch September 16, 2023 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants