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: Absolute angle takes into account BodyComponent ancestors too #2678

Merged
merged 8 commits into from
Aug 25, 2023

Conversation

maurovanetti
Copy link
Contributor

@maurovanetti maurovanetti commented Aug 25, 2023

Description

Currently, the implementation of the absoluteAngle getter in PositionComponent only takes into account PositionComponent ancestors. The implementation simply runs through the whole hierarchy summing up the relative angles.

This gives a wrong result with Forge2D because BodyComponents have angles too: in the common situation where a PositionComponent (e.g. a SpriteComponent) is the child of a BodyComponent, the BodyComponent's rotation is ignored when computing the absoluteAngle.

The fix simply introduces a new minimal interface HasAngle that both PositionComponent and BodyComponent implement (PositionComponent implements it automatically via AngleProvider), and reimplements absoluteAngle so that it considers all ancestors with an angle and not just the PositionComponent ones.

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.
  • No, this PR is not a breaking change.

@maurovanetti maurovanetti changed the title fix: absoluteAngle takes into account BodyComponent ancestors too fix: Absolute angle takes into account BodyComponent ancestors too Aug 25, 2023
@spydon
Copy link
Member

spydon commented Aug 25, 2023

Good idea! HasAngle should be named ReadOnlyAngleProvider though, to follow the new conventions set by ReadOnlySizeProvider.

@maurovanetti
Copy link
Contributor Author

Good idea! HasAngle should be named ReadOnlyAngleProvider though, to follow the new conventions set by ReadOnlySizeProvider.

Oops, I missed it. But it's got a lower-case O for some reason.

Updated.

@spydon
Copy link
Member

spydon commented Aug 25, 2023

But it's got a lower-case O for some reason.

Since it hasn't been exported previously, do you mind renaming it to ReadOnlySizeProvider and same with ReadOnlyAngleProvider, and add that one to the export too? :)

(You can sneak it into this PR too)

@maurovanetti
Copy link
Contributor Author

There we go.

Copy link
Member

@spydon spydon left a comment

Choose a reason for hiding this comment

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

Lgtm!

packages/flame/lib/effects.dart Show resolved Hide resolved
@spydon spydon merged commit 75aee76 into flame-engine:main Aug 25, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants