首页 > 解决方案 > 如何添加 1 秒延迟?

问题描述

嘿,我正在制作这个游戏,我需要 1 秒或更多的延迟?有什么想法吗?

这里我需要在 tx3 = 1000 和 cheesyx = 1000 之间延迟。

            if x < 300 and y < 300 and not duringfight:
                win.blit(cheesyt3, (tx3, ty3))
            if x < 250 and y < 250 and not duringfight:
                tx3 = 1000
                cheesyx = 1000
            if cheesyx == 1000:
                deathx -= 5
                if deathx == 600:
                    deathx += 5
                    deathmove = False
                    wmx = 1000
                    win.blit(deathtext, (dtext, 400))
                    if x > 400:
                        dtext = 1000
                        win.blit(deathhanpup, (deathx, deathy))
                        deathy = 1000

标签: timepygamedelaywait

解决方案


游戏时间

在 pygame 中,time.sleep(1)效果不好,所以你可以这样做pygame.time.delay(1),效果很好。

链接:https ://www.pygame.org/docs/ref/time.html#pygame.time.delay 。


推荐阅读