0
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()
4

1 回答 1

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.
于 2018-08-16T18:49:59.477 回答