| @property |
| defscale(self) ->Vec2: |
| """Get or set the x & y scale of the sprite as a pair of values. |
| |
| You may set it to either a single value or a pair of values: |
| |
| .. list-table:: |
| :header-rows: 0 |
| |
| * - Single value |
| - ``sprite.scale = 2.0`` |
| |
| * - Tuple or :py:class:`~pyglet,math.Vec2` |
| - ``sprite.scale = (1.0, 3.0)`` |
| |
| The two-channel version is useful for making health bars and |
| other indicators. |
| |
| .. note:: Returns a :py:class:`pyglet.math.Vec2` for |
| compatibility. |
| |
| Arcade versions lower than 3,0 used one or both of the following |
| for scale: |
| |
| * A single :py:class:`float` on versions <= 2.6 |
| * A ``scale_xy`` property and exposing only the x component |
| on some intermediate dev releases |
| |
| Although scale is internally stored as a :py:class:`tuple`, we |
| return a :py:class:`pyglet.math.Vec2` to allow the in-place |
| operators to work in addition to setting values directly: |
| |
| * Old-style (``sprite.scale *= 2.0``) |
| * New-style (``sprite.scale *= 2.0, 2.0``) |
| |
| .. note:: Negative scale values are supported. |
| |
| This applies to both single-axis and dual-axis. |
| Negatives will flip & mirror the sprite, but the |
| with will use :py:func:`abs` to report total width |
| and height instead of negatives. |
| |
| """ |
| returnVec2(*self._scale) |
| |
| @scale.setter |
| defscale(self, new_scale: Point2|AsFloat): |
| ifisinstance(new_scale, (float, int)): |
| scale_x=new_scale |
| scale_y=new_scale |
| |
| else: # Treat it as some sort of iterable or sequence |
| # Don't abstract this. Keep it here since it's a hot code path |
| try: |
| scale_x, scale_y=new_scale# type / length implicit check |
| exceptValueError: |
| raiseValueError( |
| "scale must be a tuple-like object which unpacks to exactly 2 coordinates" |
| ) |
| exceptTypeError: |
| raiseTypeError( |
| "scale must be a tuple-like object which unpacks to exactly 2 coordinates" |
| ) |
| |
| new_scale=scale_x, scale_y |
| ifnew_scale==self._scale: |
| return |
| |
| self._hit_box.scale=new_scale |
| tex_width, tex_height=self._texture.size |
| self._scale=new_scale |
| self._width=tex_width*scale_x |
| self._height=tex_height*scale_y |
| |
| self.update_spatial_hash() |
| forsprite_listinself.sprite_lists: |
| sprite_list._update_size(self) |
This might just be about reverting #2021
The vector sprite perf testing showed 2.x cost. We should quickly review the cost of the sprite scale changes before we release.
arcade/arcade/sprite/base.py
Lines 263 to 339 in fa6e938
We might just have to revert these changes for now and bake them into the new experimental sprites.
See : #2184