Skip to content

Commit 1c5a182

Browse files
authored
Sprite: Clamp alpha to 0-255 in setter (#2435)
1 parent 4edcf7e commit 1c5a182

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

arcade/sprite/base.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,12 +512,18 @@ def color(self, color: RGBOrA255):
512512

513513
@property
514514
def alpha(self) -> int:
515-
"""Get or set the alpha value of the sprite"""
515+
"""
516+
Get or set the alpha value of the sprite.
517+
518+
Will be clamped to the range 0-255.
519+
"""
516520
return self._color[3]
517521

518522
@alpha.setter
519523
def alpha(self, alpha: int):
520-
self._color = Color(self._color[0], self._color[1], self._color[2], int(alpha))
524+
self._color = Color(
525+
self._color[0], self._color[1], self._color[2], max(0, min(255, int(alpha)))
526+
)
521527

522528
for sprite_list in self.sprite_lists:
523529
sprite_list._update_color(self)

0 commit comments

Comments
 (0)