Python 标题屏幕未运行Pygame
我试图为我正在制作的游戏创建一个标题屏幕,但当我运行程序时,它只是一个黑色画布。没有标题,一切都很好,游戏(这是一个迷宫)运行完美,但如果我试图添加标题fcn,一切都会一团糟。 运行我的程序时,我正在呼叫:Python 标题屏幕未运行Pygame,python,pygame,Python,Pygame,我试图为我正在制作的游戏创建一个标题屏幕,但当我运行程序时,它只是一个黑色画布。没有标题,一切都很好,游戏(这是一个迷宫)运行完美,但如果我试图添加标题fcn,一切都会一团糟。 运行我的程序时,我正在呼叫: game_intro() game_loop() #the fcn that stores my game code 这是我的标题fcn代码: def game_intro(): intro = True while intro == True: for
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)
您需要在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)
您的
game\u intro
功能将在初始循环检查退出事件时暂停。下面的代码永远不会运行--它应该缩进到与for
循环相同的级别,以便在处理事件后运行。然后,您需要某种方法退出while
循环,可能会在按键或其他事件中将intro
设置为False。您的game\u intro
功能将在初始循环检查退出事件时暂停。下面的代码永远不会运行--它应该缩进到与for
循环相同的级别,以便在处理事件后运行。然后,您需要某种方法退出while
循环,可能在按键或其他事件中将intro
设置为False。