-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Add a Viewport method to get automatically computed 2D stretch transform #80965
Add a Viewport method to get automatically computed 2D stretch transform #80965
Conversation
3ba9917
to
a08fcec
Compare
91fdbfd
to
b0ce67a
Compare
b0ce67a
to
56e0ee6
Compare
56e0ee6
to
6f3203c
Compare
6f3203c
to
41d1342
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the adjusted documentation I think this should be good to go.
`Viewport.get_stretch_transform()` returns the automatically computed 2D stretch transform. Combined with `Transform2D.get_scale()`, this is useful when using the `canvas_items` stretch mode in a project. There are many situations where knowing this factor is useful: - Divide Camera2D zoom to keep the size of the 2D game world identical regardless of the 2D scale factor (so that UI elements can still be scaled). - Make certain controls always drawn at 1:1 scale (e.g. for the crosshair in a FPS). This is done by dividing the Control node's scale by the scale factor.
41d1342
to
0cf99cf
Compare
I've force-pushed a commit that amends the commit message to describe more accurately what it does now (expose the stretch transform, not just the scale). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation looks correct.
Thanks! |
Viewport.get_stretch_transform()
returns the automatically computed 2D stretch transform. Combined withTransform2D.get_scale()
, this is useful when using thecanvas_items
stretch mode in a project.There are many situations where knowing this factor is useful:
Testing project: test_scale_factor_2.zip
Preview
Top displays a GDScript implementation as shown in the proposal. Bottom displays the new implementation.