arcade
arcade copied to clipboard
Name scale properties on Sprites to things that make sense
What does it do?
- Allows setting
scaleto afloatfor backwards compatible codefeel/easy proportional scaling - Getting
scalereturns atuple[float, float] - Renames
scale->scale_x - Renames
scale_xy->scale - Adds
scale_y
Why should this be done?
- The current implementation lies to you.
scaleas it is returnsscale_x, which is incorrect if x/y are scaled independently. - There is precedent.
Spritecurrently returnsposition¹ as a 2-tuple, andcenter_xandcenter_yas floats. - Learning wrong is worse than not learning. The current implementation is more confusing for children in the long run. Most game libraries represent
scalein both dimensions, and Arcade should aim to provide transferable knowledge. - It's confusing for a developer. If you are a games dev, understanding why
.scalereturns x,scale_yreturns y,scale_xyreturns a tuple, but settingscalesets both x and y, is very confusing and makes code harder to read and reeks havoc on codefeel.
¹I'd argue position should be center as well, but that's for another day.
TL;DR: This will be a non-breaking change & efficiency upgrade with pyglet 2.1, which seems to be coming sooner than expected.
Benefits:
sprite_instance.scale *= 2.0will work with scalars as it does nowsprite_instance.scale *= 2.0, 3.0:- It'll just work with arbitrary sequences (pyglet 2.1 feature)
- Cleaner
- More efficient than multiplying
center_xandcenter_yindividually (both iterate over and update all referencingSpriteLists) - More reliable than doing math on the individual axes yourself
Steps required:
- [x] Bump to pyglet 2.1 (#2043)
- [x] Make
BasicSprite.scalereturn pyglet 2.1's tuple-basedVec2s - [ ] Improve doc to use/review position to teach tuples, then lead into scale
- cute diagram with scale x and scale y, stretching a snake image
- scale example with interactive GUI sliders to scale sprite
- add links to healthbar examples
- [ ] Revert any example temp fixes to pass CI / typing
What about the initializer? Should scale still only be a float there?
Imo, it could be either without an isinstance check:
if hasattr(scale, "__len__"):
self._scale = Vec2(*scale)
else:
self._scale = Vec2(scale, scale)
I resolved the conflicts. There was a lot of changes to unit test so these needs to be looked into.