Python 有人知道为什么我在运行此代码时会出现一个无响应的pygame窗口吗
您的缩进已关闭,或者至少是唯一明显的问题。我试过运行,但第5行的设置未定义。在您给出的内容中没有定义其他类。这里有正确的缩进。(必须切换Python 有人知道为什么我在运行此代码时会出现一个无响应的pygame窗口吗,python,pygame,Python,Pygame,您的缩进已关闭,或者至少是唯一明显的问题。我试过运行,但第5行的设置未定义。在您给出的内容中没有定义其他类。这里有正确的缩进。(必须切换pygame.display.flip()和ship.blitme()) 您的缩进已关闭,或者至少是唯一明显的问题。我试过运行,但第5行的设置未定义。在您给出的内容中没有定义其他类。这里有正确的缩进。(必须切换pygame.display.flip()和ship.blitme()) 由于while:块,您将永远无法到达超过sys.exit()行的任何对象。退出w
pygame.display.flip()
和ship.blitme()
)
您的缩进已关闭,或者至少是唯一明显的问题。我试过运行,但第5行的设置未定义。在您给出的内容中没有定义其他类。这里有正确的缩进。(必须切换
pygame.display.flip()
和ship.blitme()
)
由于
while:
块,您将永远无法到达超过sys.exit()
行的任何对象。退出while循环的唯一方法是退出游戏。检查缩进。您尚未将某些行放入while
循环中。由于while True:
块,您将永远无法到达任何超过sys.exit()
行的内容。退出while循环的唯一方法是退出游戏。检查缩进。您尚未将某些行置于while
循环中。
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()
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.