[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Resizing a sprite at runtime
On Jun 22, 2007, at 10:34 AM, Michael Sullivan wrote:
If I have an image loaded into a variable, is there a way I can
display
the image larger than it actually is in the file? I have a sprite
that's 80x40. The other sprites on the screen are 64x64, and the
first
sprite looks tiny compared to the others, so I wanted to make it
appear
bigger than 80x40. Can anyone help me out?
I assume you want to keep the same aspect ratio, and do smooth (non
jaggy) scaling. Here's an example function that scales an input image
to fit in a square of a given size.
def resize(surface, size):
scale = size / float(max(surface.get_rect().size))
return pygame.transform.rotozoom(surface, 0, scale)
Note using rotozoom will "upsample" the input surface to 32bpp
regardless of the input surface bitsize.
hth,
-Casey