Pygame日夜机修工不工作

2024-04-20 16:23:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着为我的游戏做一个白天/晚上的功能,每10分钟背景就会改变一次,但是当我运行它的时候,它就在启动时崩溃了。这是错误代码。你知道吗

bg = pygame.image.load("bg.png")
bgg = pygame.image.load("bbg.png")

def bg1():
    screen.blit(bg, (0, 0))

def bbg1():
    screen.blit(bbg, (0, 0))

def fbg():
    bg1()
    pygame.time.wait(10000)
    bbg1()


screen.fill((0,0,0))
fbg()

我有屏幕填充((0,0,0))因为那里也有一个矩形,它在移动。你知道吗


Tags: image功能游戏pngdefloadscreenpygame
1条回答
网友
1楼 · 发布于 2024-04-20 16:23:14

您的问题是pygame.time.wait调用只是在10000毫秒内停止当前线程的执行。你需要另一个线程来运行游戏。你知道吗

documentation表示:

pygame.time.wait()

Will pause for a given number of milliseconds. This function sleeps the process to share the processor with other programs. A program that waits for even a few milliseconds will consume very little processor time. It is slightly less accurate than the pygame.time.delay() function.

相关问题 更多 >