Skip to content

Commit

Permalink
allow actors to have an alpha value
Browse files Browse the repository at this point in the history
  • Loading branch information
megonemad1 authored and lordmauve committed Sep 19, 2018
1 parent f2020c1 commit 3454536
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pgzero/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Actor:

_anchor = _anchor_value = (0, 0)
_angle = 0.0
_opacity = 1

def __init__(self, image, pos=POS_TOPLEFT, anchor=ANCHOR_CENTER, **kwargs):
self._handle_unexpected_kwargs(kwargs)
Expand Down Expand Up @@ -185,6 +186,18 @@ def angle(self, angle):
self._anchor = transform_anchor(ax, ay, w, h, angle)
self.pos = p

@property
def opacity(self):
return self._opacity

@opacity.setter
def opacity(self, opacity):
self._opacity = opacity
alpha_img = pygame.Surface(self._orig_surf.get_rect().size, pygame.SRCALPHA)
alpha_img.fill((255, 255, 255, opacity))
alpha_img.blit(self._orig_surf, (0, 0), special_flags=pygame.BLEND_RGBA_MULT)
self._surf = alpha_img

@property
def pos(self):
px, py = self.topleft
Expand Down

0 comments on commit 3454536

Please sign in to comment.