Pygame 缩放后重置图片
Pygame reset an Image after scaling it
我试图通过将鼠标移到图像上来放大图像,并在移开鼠标时使其恢复到原始大小。
例如:
if ImageRect.collidepoint(mouseX,mouseY):
Image = pygame.transform.scale(Image, (100,100))
else:
Image = pygame.transform.scale(Image, (64,64)) #actual size of Image
但是在上面移动鼠标10次后,图像变得奇怪了。
我该如何解决这个问题?
Some of the transforms are considered destructive. These means every
time they are performed they lose pixel data. Common examples of this
are resizing and rotating. For this reason, it is better to
retransform the original surface than to keep transforming an image
multiple times. (For example, suppose you are animating a bouncing
spring which expands and contracts. If you applied the size changes
incrementally to the previous images, you would lose detail. Instead,
always begin with the original image and scale to the desired size.)
直接取自pygame.transform documentation
变通
不要每次都更改原始图像。相反,每次它们碰撞时,只在旧图像之上显示一个新图像(因为它是一个更大的图像,旧图像不会被显示)。或者,您可以只隐藏旧图像。
示例:
if ImageRect.collidepoint(mouseX,mouseY):
Image2 = pygame.transform.scale(Image, (100,100))
我试图通过将鼠标移到图像上来放大图像,并在移开鼠标时使其恢复到原始大小。 例如:
if ImageRect.collidepoint(mouseX,mouseY):
Image = pygame.transform.scale(Image, (100,100))
else:
Image = pygame.transform.scale(Image, (64,64)) #actual size of Image
但是在上面移动鼠标10次后,图像变得奇怪了。 我该如何解决这个问题?
Some of the transforms are considered destructive. These means every time they are performed they lose pixel data. Common examples of this are resizing and rotating. For this reason, it is better to retransform the original surface than to keep transforming an image multiple times. (For example, suppose you are animating a bouncing spring which expands and contracts. If you applied the size changes incrementally to the previous images, you would lose detail. Instead, always begin with the original image and scale to the desired size.)
直接取自pygame.transform documentation
变通
不要每次都更改原始图像。相反,每次它们碰撞时,只在旧图像之上显示一个新图像(因为它是一个更大的图像,旧图像不会被显示)。或者,您可以只隐藏旧图像。
示例:
if ImageRect.collidepoint(mouseX,mouseY):
Image2 = pygame.transform.scale(Image, (100,100))