Python/Pygame 如何让某些东西在设定的时间后从屏幕上消失?

Python/Pygame How to make something disappear off of screen after a set amount of time?

我想知道是否有某种代码可以让某些东西在设定的时间后从屏幕上消失?像是游戏介绍之类的东西?

您应该使用 pygame.time.Clock 来记录时间的流逝。

您使用了 标签,所以使用 threading.Timer 对象在一段时间后调用一个函数:

class Menu:
    def __init__(self):
        self.active = True

        # start a timer for the menu
        Timer(3, self.reset).start()

    def update(self, scr):
        if self.active:
            surf = pygame.Surface((100, 100))
            surf.fill((255, 255, 255))
            scr.blit(surf, (270, 190))

    def reset(self):
        self.active = False

menu = Menu()

while True:
    pygame.display.update()
    queue = pygame.event.get()
    scr.fill((0, 0, 0))

    for event in queue:
        if event.type == QUIT:
            pygame.quit(); sys.exit()

    menu.update(scr)