有谁知道为什么我在运行此代码时得到一个无响应的pygame窗口

时间:2018-08-16 18:41:11

标签: python pygame

def run_game():
    """Initialise the game and create a screen object."""
    pygame.init() 
    ai_settings = Settings()

    screen = pygame.display.set_mode((ai_settings.screen_width,ai_settings.screen_height)) 

    ship = Ship(screen)

    pygame.display.set_caption("Alien Invasion")

    while True:
        for event in pygame.event.get():  
            if event.type == pygame.QUIT:
                sys.exit()

    #Redraw the screen for each pass through the loop. ie fill the screen with colour.
    screen.fill(ai_settings.bg_colour) 

    #Make the most recently drawn screen visible.
    pygame.display.flip() 
    # Will update the screen as game elements move around. Making the game look smooth.


    ship.blitme() # added after background so appears ontop of it.


run_game()

1 个答案:

答案 0 :(得分:2)

您的缩进不可用,或者至少是唯一明显的问题。我尝试运行,但第5行的设置未定义。您提供的课程中还没有定义其他班级。这里是正确的缩进。 (必须切换pygame.display.flip()ship.blitme()

while True:
    for event in pygame.event.get():  
        if event.type == pygame.QUIT:
            sys.exit()

    #Redraw the screen for each pass through the loop. ie fill the screen with colour.
    screen.fill(ai_settings.bg_colour) 
    ship.blitme() # added after background so appears ontop of it.
    #Make the most recently drawn screen visible.
    pygame.display.flip() 
    # Will update the screen as game elements move around. Making the game look smooth.