How can I resize a Surface
object in Pygame? Is there a way to bind a surface object into a Rect
object, so that resizing the rect would also resize the surface (with Rect.inflate_ip
method for an example)?
There's no way to do this automatically, so if you want some sort of automation for the surface rescaling, you'd need to write your own wrapper class around pygame.Rect
, that owns a rectangle, and takes in a surface, and resizes the surface when a method of the wrapper is called.
The resizing function you are looking for is pygame.transform.scale
. Pass it a surface and the new size you want, and it will return a new surface, or place the result into an already created surface (this is faster).
-
\$\begingroup\$ Is
scale
method not only for resizing of images at the toplevel? Is it ok to use it continuously (say by setting a timer) to resize many surfaces in the main loop? \$\endgroup\$ – user78884 Nov 29 '18 at 14:41 -
\$\begingroup\$ You can use it wherever, just note that it can be a bit slow, but that is unavoidable with a software renderer like pygame. \$\endgroup\$ – Tyyppi_77 Nov 29 '18 at 15:33