在一段时间后更改 pygame 中的图像

change an image in pygame after a length of time

嗨,我是这个网站的新手。 问题来了。

目前,该程序会显示一张本应是启动屏幕的图像三秒钟。 然后我希望它停止显示第一张图像并连续显示另一张图像。 我正在使用 pygame 1.9.1 版和 python 2.7.9 版。 代码如下。 也先谢谢了。

 import pygame, sys
from pygame.locals import *
pygame.init()

gameDisplay=pygame.display.set_mode((600,600))
pygame.display.set_caption("Platypus")

white=255,255,255
black=0,0,0
red=255,0,0

important_platypus=pygame.image.load("C:/Users/Sarah_2/Pictures/no_one_knows_why_Duck_Billed_Platypi_are_important.jpg")
important_platypus=pygame.transform.scale(important_platypus,(600,600))

gameExit=False
while not gameExit:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            gameExit = True

    gameDisplay.blit(important_platypus, (0, 0) )

    pygame.display.update()

pygame.quit()
quit()

time.sleep就是你想要的功能。下面是一个完整的例子:

 import pygame, sys 
 from pygame.locals import * 
 pygame.init() 
 gameDisplay=pygame.display.set_mo de((600,600))
 pygame.display.set_caption ("Platypus")
 time.sleep(3)
 gameDisplay=pygame.display.set_mo de((600,600)) 
 pygame.display.set_caption ("second image")