0
screen = pygame.display.set_mode([800,600])

pygame.display.set_caption("example")

background = pygame.Surface(screen.get_size())

background.fill(white)

clock = pygame.time.Clock()

background_image = pygame.image.load("example.jpg").convert()

background_position=[30,30]


done = False

while done == False:
    clock.tick(10)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done= True

screen.blit(background_image,background_position)

pygame.display.flip()

pygame.quit()

所以我一直在尝试在pygame中加载图像,可能很简单,我有点让它工作但图像实际上并没有出现在主表面上,当我关闭窗口时它只出现2秒。我是否忘记在某处进行 blit 或更新?谢谢!

4

1 回答 1

2

尝试在 while 循环中移动一些行:

while done == False:
    clock.tick(10)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done= True

    screen.blit(background_image,background_position)

    pygame.display.flip()

您的图像未绘制,因为您的程序正忙于 while 循环,从未达到实际的绘图指令。当你用 quit 退出它时,最后三行被执行,向你展示你的照片(片刻)。

于 2012-01-15T19:02:22.997 回答