pygame.transform.scale()
does not scale the input Surface itself. It creates a new surface and does a scaled "blit" to the new surface. The new surface is returned by the return value:
pygame.transform.scale()
does:
- Creates a new surface (
newSurface
) with size (width, height)
.
- Scale and copy
Surface
to newSurface
.
- Return
newSurface
.
The destination surface is a pygame.Surface
where the scaled surface is copied to. That is quicker, because the memory for the Surface has not to be allocated.
It DestSurface
is set, then pygame.transform.scale()
does:
- Scale and copy
Surface
to the DestSurface
.
- Return
DestSurface
.
For that reason, the size of DestSurface
has to be (width, height)
, the format of DestSurface
has the same as the format of Surface
.
A possible use case is if you have to continuously scale something to a fixed size in the main application loop (e.g. if the surface is dynamically generated). In the following surf
is assumed to be a surface object:
while True:
# [...]
scaledSurf = pygame.transform.scale(surf, (100, 100))
window.blit(scaledSurf, (x, y)
The code can be improved by using the DestSurface
parameter:
scaledSurf = pygame.Surface((100, 100))
while True:
# [...]
pygame.transform.scale(surf, (100, 100), scaledSurf)
window.blit(scaledSurf, (x, y)
That is probably a rare case. In general you should try to scale the surfaces at the initialization, rather than continuously in the application loop and to use the scaled surfaces in the loop.
Do not try to use the parameter compulsively and do not "construct" a use case for the DestSurface
parameter. Do it the other way around. Write your application and make it run. Then investigate whether the DestSurface
parameter can be an improvement for your specific use case.