标题屏幕未运行Pygame

时间:2017-06-08 22:31:40

标签: python 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)

我感谢任何帮助或建议!

1 个答案:

答案 0 :(得分:0)

你需要在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)