Skip to content

Commit

Permalink
Sprite: Clamp alpha to 0-255 in setter (#2435)
Browse files Browse the repository at this point in the history
  • Loading branch information
einarf authored Oct 25, 2024
1 parent 4edcf7e commit 1c5a182
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions arcade/sprite/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,18 @@ def color(self, color: RGBOrA255):

@property
def alpha(self) -> int:
"""Get or set the alpha value of the sprite"""
"""
Get or set the alpha value of the sprite.
Will be clamped to the range 0-255.
"""
return self._color[3]

@alpha.setter
def alpha(self, alpha: int):
self._color = Color(self._color[0], self._color[1], self._color[2], int(alpha))
self._color = Color(
self._color[0], self._color[1], self._color[2], max(0, min(255, int(alpha)))
)

for sprite_list in self.sprite_lists:
sprite_list._update_color(self)
Expand Down

0 comments on commit 1c5a182

Please sign in to comment.