arcade icon indicating copy to clipboard operation
arcade copied to clipboard

Name scale properties on Sprites to things that make sense

Open DigiDuncan opened this issue 1 year ago • 4 comments

What does it do?

  • Allows setting scale to a float for backwards compatible codefeel/easy proportional scaling
  • Getting scale returns a tuple[float, float]
  • Renames scale -> scale_x
  • Renames scale_xy -> scale
  • Adds scale_y

Why should this be done?

  • The current implementation lies to you. scale as it is returns scale_x, which is incorrect if x/y are scaled independently.
  • There is precedent. Sprite currently returns position¹ as a 2-tuple, and center_x and center_y as floats.
  • Learning wrong is worse than not learning. The current implementation is more confusing for children in the long run. Most game libraries represent scale in both dimensions, and Arcade should aim to provide transferable knowledge.
  • It's confusing for a developer. If you are a games dev, understanding why .scale returns x, scale_y returns y, scale_xy returns a tuple, but setting scale sets 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.

DigiDuncan avatar Mar 13 '24 06:03 DigiDuncan

TL;DR: This will be a non-breaking change & efficiency upgrade with pyglet 2.1, which seems to be coming sooner than expected.

Benefits:

  1. sprite_instance.scale *= 2.0 will work with scalars as it does now
  2. sprite_instance.scale *= 2.0, 3.0:

Steps required:

  • [x] Bump to pyglet 2.1 (#2043)
  • [x] Make BasicSprite.scale return pyglet 2.1's tuple-based Vec2s
  • [ ] Improve doc to use/review position to teach tuples, then lead into scale
    1. cute diagram with scale x and scale y, stretching a snake image
    2. scale example with interactive GUI sliders to scale sprite
    3. add links to healthbar examples
  • [ ] Revert any example temp fixes to pass CI / typing

pushfoo avatar Mar 15 '24 10:03 pushfoo

What about the initializer? Should scale still only be a float there?

einarf avatar Apr 16 '24 02:04 einarf

Imo, it could be either without an isinstance check:

if hasattr(scale, "__len__"):
    self._scale = Vec2(*scale)
else:
    self._scale = Vec2(scale, scale)

pushfoo avatar Apr 16 '24 02:04 pushfoo

I resolved the conflicts. There was a lot of changes to unit test so these needs to be looked into.

einarf avatar Jun 30 '24 02:06 einarf