问题描述
在这里,我正在尝试移动在屏幕上被弄脏的移动,但图像移动而没有清除前一个
balloon=pygame.image.load("BALLON 1".png)
Bal_x=0
while true:
for event in pygame.event.get():
if event.type==pygame.QUIT:
pygame.quit()
sys.exit()
Bal_x+=1
screen.blit(BALLON,(Bal_x.120))
pygame.display.update()
clock.tick(120)
解决方法
您必须在每一帧中使用 pygame.Surface.fill
清除显示:
balloon=pygame.image.load("BALLON 1".png)
Bal_x=0
while true:
for event in pygame.event.get():
if event.type==pygame.QUIT:
pygame.quit()
sys.exit()
Bal_x+=1
screen.fill((0,0)) # <--- this is missing
screen.blit(BALLON,(Bal_x.120))
pygame.display.update()
clock.tick(120)
典型的 PyGame 应用程序循环必须:
- 通过调用
pygame.event.pump()
或pygame.event.get()
来处理事件。 - 根据输入事件和时间(分别为帧)更新游戏状态和对象位置
- 清除整个显示或绘制背景
- 绘制整个场景(
blit
所有对象) - 通过调用
pygame.display.update()
或pygame.display.flip()
来更新显示 - 使用
pygame.time.Clock.tick
限制每秒帧数以限制 CPU 使用率