How can I move the ball instead of leaving a trail all over the screen in pygame?

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()

    # [...]

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:

Leave a Comment