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!: Added anchor for the Viewport #1611

Merged
merged 11 commits into from
May 11, 2022
Merged

Conversation

st-pasha
Copy link
Contributor

@st-pasha st-pasha commented May 8, 2022

Description

  • The Viewport now has its own anchor;
  • The coordinate system of the Viewport now always has the origin in the top-left corner of its bounding box (previously it was in the center) -- similar to the local coordinate system of a PositionComponent.

Checklist

  • The title of my PR starts with a Conventional Commit prefix (fix:, feat:, docs: etc).
  • I have read the Contributor Guide and followed the process outlined for submitting PRs.
  • 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.

Breaking Change

  • Yes, this is a breaking change.
  • [-] No, this is not a breaking change.

Related Issues

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.

Very nice, I think topLeft makes more sense to be the default too (noticed when I created this DartPad game).

Comment on lines +114 to +117
final viewportPoint = Vector2(
point.x - viewport.position.x + viewport.anchor.x * viewport.size.x,
point.y - viewport.position.y + viewport.anchor.y * viewport.size.y,
);
Copy link
Member

Choose a reason for hiding this comment

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

is this the same as: point - anchor.translate(viewport.position, viewport.size) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could be, but I don't really understand what is anchor.translate(), and when it can be used.

canvas.translate(
viewport.position.x - viewport.anchor.x * viewport.size.x,
viewport.position.y - viewport.anchor.y * viewport.size.y,
);
Copy link
Member

Choose a reason for hiding this comment

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

is this the same as canvas.translateVector(anchor.translate(viewport.position, viewport.size)?

we could even have a function to combine an anchor and a viewport that calls anchor.translate

@spydon spydon enabled auto-merge (squash) May 11, 2022 17:50
@spydon spydon merged commit c3bb14b into flame-engine:main May 11, 2022
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.

5 participants