diff --git a/doc/builtins.rst b/doc/builtins.rst index 21aeb12d..4c63e1ab 100644 --- a/doc/builtins.rst +++ b/doc/builtins.rst @@ -591,6 +591,24 @@ Remember that angles loop round, so 0 degrees == 360 degrees == 720 degrees. Likewise -180 degrees == 180 degrees. +Scaling +''''''' +.. versionadded:: 1.3 + +To resize and Actor, use ``scale_up`` and ``scale_down``. These will change the +dimensions of the Actor by a given factor. For example, ``scale_up(2)`` +will increase Actor's width and height 2x.:: + + alien = Actor('alien') + alien.scale_up(2) + + def draw(): + alien.draw() + +Scaling the Actor does not change the file size of the image. Significantly +scaling images with large file sizes will not reduce the memory taken by the +images.:: + Distance and angle to ''''''''''''''''''''' diff --git a/pgzero/actor.py b/pgzero/actor.py index 165478d3..960fb2ba 100644 --- a/pgzero/actor.py +++ b/pgzero/actor.py @@ -353,5 +353,18 @@ def distance_to(self, target): dy = ty - myy return sqrt(dx * dx + dy * dy) + def scale_up(self, value): + """Scales up the image by a factor of the inputted value.""" + self._orig_surf = pygame.transform.scale(self._surf, (int(self._surf.get_width() * value), int(self._surf.get_height() * value))) + self._surf = self._orig_surf + self._update_pos() + + def scale_down(self, value): + """Scales down the image by a factor of the inputted value.""" + self._orig_surf = pygame.transform.scale(self._surf, (self._surf.get_width() // value, self._surf.get_height() // value)) + self._surf = self._orig_surf + self._update_pos() + + def unload_image(self): loaders.images.unload(self._image_name)