Skip to content

Commit

Permalink
fix: image size (#43)
Browse files Browse the repository at this point in the history
* fix: image size

* fix: also add ability for image to be dynamically set on an existing image
  • Loading branch information
koen1711 authored Dec 7, 2024
1 parent fb122d7 commit 2f9a743
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions play/objects/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,26 @@ def __init__(
def update(self):
"""Update the image's position, size, angle, and transparency."""
if self._should_recompute:
self._image = pygame.transform.scale(self._image, (self.width, self.height))
self._image = pygame.transform.scale(
self._image,
(self.width * self.size // 100, self.height * self.size // 100),
)
self._image = pygame.transform.rotate(self._image, self.angle)
self._image.set_alpha(self.transparency)
self._image.set_alpha(self.transparency * 2.55)
self.rect = self._image.get_rect()
pos = convert_pos(self.x, self.y)
self.rect.center = pos
super().update()

@property
def image(self):
"""Return the image."""
return self._image

@image.setter
def image(self, image: str):
"""Set the image."""
if not os.path.isfile(image):
raise FileNotFoundError(f"Image file '{image}' not found.")
self._image = pygame.image.load(image)
self.update()

0 comments on commit 2f9a743

Please sign in to comment.