我是 Pygame 的新手,看过一些游戏的教程。我遇到的问题是,除非我关闭 window ,否则表面颜色不会改变。我见过很多人在游戏循环中将填充放在下面,背景颜色立即改变,但就我而言,它保持黑色,直到我按下关闭按钮。然后它改变颜色并退出。
import pygame
pygame.init()
blue=(0,0,255)
screen=pygame.display.set_mode((500,500))
pygame.display.set_caption('virus')
icon= pygame.image.load('virus-face.png')
pygame.display.set_icon(icon)
running=True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running=False
screen.fill(blue)
pygame.display.update()
pygame.quit()
最佳答案
这是Indentation的问题.
screen.fill(blue)
和 screen.fill(blue)
必须在应用程序循环中完成:
running=True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running=False
screen.fill(blue)
pygame.display.update()
pygame.quit()
关于python - Pygame 中的表面颜色仅在窗口关闭后才会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58964238/