pygame 中的上一个屏幕未清除

问题描述

在这里,我正在尝试移动在屏幕上被弄脏的移动,但图像移动而没有清除前一个

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)

It moves like in the image

解决方法

您必须在每一帧中使用 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 应用程序循环必须: