Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/pgzero/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ def _set_opacity(actor, current_surface):
class Actor:
EXPECTED_INIT_KWARGS = SYMBOLIC_POSITIONS
DELEGATED_ATTRIBUTES = [
a for a in dir(rect.ZRect) if not a.startswith("_")
a for a in dir(rect.ZRect) if not a.startswith("_") and
# To prevent rect width and height being accessible without those
# implicating changes to the actors' image width and height.
not a == "width" and not a == "height"
]

function_order = [_set_opacity, _set_angle]
Expand Down Expand Up @@ -240,6 +243,24 @@ def _calc_anchor(self):
else:
self._anchor = transform_anchor(ax, ay, ow, oh, self._angle)

@property
def width(self):
return self._width

@width.setter
def width(self, _):
print("WARNING: The width of an actor can't be set directly. Change "
"the actors image to change its dimensions.")

@property
def height(self):
return self._height

@height.setter
def height(self, _):
print("WARNING: The height of an actor can't be set directly. Change "
"the actors image to change its dimensions.")

@property
def angle(self):
return self._angle
Expand All @@ -252,8 +273,8 @@ def angle(self, angle):
ra = radians(angle)
sin_a = sin(ra)
cos_a = cos(ra)
self.height = abs(w * sin_a) + abs(h * cos_a)
self.width = abs(w * cos_a) + abs(h * sin_a)
self._height = abs(w * sin_a) + abs(h * cos_a)
self._width = abs(w * cos_a) + abs(h * sin_a)
ax, ay = self._untransformed_anchor
p = self.pos
self._anchor = transform_anchor(ax, ay, w, h, angle)
Expand Down Expand Up @@ -331,7 +352,7 @@ def image(self, image):

def _update_pos(self):
p = self.pos
self.width, self.height = self._orig_surf.get_size()
self._width, self._height = self._orig_surf.get_size()
self._calc_anchor()
self.pos = p

Expand Down