且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在pygame中使球移动而不是拉伸?

更新时间:2023-11-22 22:58:10

您必须使用 pygame.Surface.fill:

You have to clear the display in every frame with pygame.Surface.fill:

while True:
    # [...]

    screen.fill(0) # <---

    main.draw_elements()
    main.move_ball()
    main.ball.x_pos += main.ball.speed
    pygame.display.flip()

    # [...]

绘制的所有内容都绘制在目标表面上.整个场景在每一帧中重新绘制.因此,需要在应用程序循环中的每一帧开始时清除显示.典型的 PyGame 应用程序循环必须:

Everything that is drawn is drawn on the target surface. The entire scene is redraw in each frame. Therefore the display needs to be cleared at the begin of every frame in the application loop. The typical PyGame application loop has to: