标题屏幕未运行 Pygame



我正在尝试为我正在制作的游戏创建一个标题屏幕,但是当我运行程序时,它只是一个黑色画布。没有标题,一切正常,游戏(这是一个迷宫(运行良好,但如果我尝试添加我的标题 fcn,一切都会搞砸。运行我的程序时,我调用:

game_intro()
game_loop() #the fcn that stores my game code 

这是我的标题 fcn 代码:

def game_intro():
    intro = True
    while intro == True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
    screen.fill((WHITE))
    largeText = pygame.font.Font(None, 115)
    TextSurf, TextRect = text_objects("H&D: Hedges and Dragons", largeText)
    TextRect.center = ((DISPLAY_WIDTH/2), (DISPLAY_HEIGHT/2))
    screen.blit(TextSurf, TextRect)
    pygame.display.update()
    clock.tick(FPS)

我感谢任何帮助或建议!

你需要在

while 循环之前初始化 pygame:

def game_intro():
    pygame.init()
    screen = pygame.display.set_mode((1000, 900))
    intro = True
    while intro: #do not need intro == True
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
               pygame.quit()
               quit()
    screen.fill((WHITE))
    largeText = pygame.font.Font(None, 115)
    TextSurf, TextRect = text_objects("H&D: Hedges and Dragons", largeText)
    TextRect.center = ((DISPLAY_WIDTH/2), (DISPLAY_HEIGHT/2))
    screen.blit(TextSurf, TextRect)
    pygame.display.update()
    clock.tick(FPS)

最新更新