【问题标题】:Previous screen is not clearing in pygame [duplicate]pygame中没有清除上一个屏幕[重复]
【发布时间】:2021-06-20 08:53:12
【问题描述】:

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

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

【问题讨论】:

  • 问题解决了吗?

标签: python python-3.x pygame 2d blit


【解决方案1】:

您必须在每一帧中使用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, 0)) # <--- this is missing

    screen.blit(BALLON,(Bal_x.120))
    pygame.display.update()
    clock.tick(120)

典型的 PyGame 应用程序循环必须:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-24
    • 2018-12-20
    • 2011-04-08
    • 1970-01-01
    • 1970-01-01
    • 2016-01-15
    • 1970-01-01
    • 2022-01-23
    相关资源
    最近更新 更多