所以是的,我正在构建游戏。从一开始我忘了把屏幕调整大小。并且知道我正在尝试包含它。我得到了几乎所有工作它调整图像大小,但他们变得很奇怪。
屏幕设置
size = [1600, 1000]
screen = pygame.display.set_mode((1600, 1000), HWSURFACE | DOUBLEBUF | RESIZABLE)
pygame.display.set_caption('#Vote me for the ruler of the world!!!')
clock = pygame.time.Clock()
当窗口调整大小时,程序会做什么
elif event.type == VIDEORESIZE:###########IF WINDOW GETS REZISED
screen = pygame.display.set_mode(event.dict['size'], HWSURFACE | DOUBLEBUF | RESIZABLE)
pygame.display.flip()
if GUIstatus == 1:
screen.fill((color,color,color))
screen.blit(pygame.transform.scale(spaceGUI, event.dict['size']),(0,0))
screen.blit(pygame.transform.scale(screenMonitor,event.dict['size']),(0,0))
screen.blit(pygame.transform.scale(button,event.dict['size']),(1425,10))
screen.blit(pygame.transform.scale(button,event.dict['size']),(1425,75))
screen.blit(pygame.transform.scale(button,event.dict['size']),(1425,140))
screen.blit(pygame.transform.scale(text_button1,event.dict['size']),(1436, 30))
pygame.display.flip()
那么这里发生了什么?
修改 这是原始图像绘制的代码。 (主循环)
done = False
while done == False:
pygame.event.pump()
mouse_x,mouse_y = pygame.mouse.get_pos()
timer += 1
if timer > 99:
timer = 0
if GUIstatus == 1: ####HERE IS THE ORIGINAL IMAGE DRAWING
screen.blit(spaceGUI,(0,0))
screen.blit(screenMonitor,(0,0))
screen.blit(button,(1425,10))
screen.blit(button,(1425,75))
screen.blit(button,(1425,140))
screen.blit(text_button1, (1436, 30))
if techTreeRect.collidepoint(mouse_x,mouse_y) and event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
print("techtree")
if contactsRect.collidepoint(mouse_x,mouse_y) and event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
print("Contacts")
GUIstatus = 3
screen.fill((color,color,color))
答案 0 :(得分:0)
当您调整屏幕大小时,您只需对缩放的图像进行一次blitting,然后返回到原始图像的blitting。要解决此问题,您可以将图像重新绑定为缩放版本。如果您的图像是基于像素的,则可能会使图像失真,因此您需要对原始图像进行引用并对其进行转换,而不是转换已经转换的图像。
因此,在您的VIDEORESIZE
事件中,您可以执行以下操作:
spaceGUI = pygame.transform.scale(spaceGUI, event.dict['size'])
对于每张图片,而不是blitting。