I want to create a trail of every ball i create, but i cant think of anything that would help me to do it
def create_balls(space,x,y):
body = pymunk.Body()
body.position = (x,y)
shape = pymunk.Circle(body, 10)
shape.density = 1
shape.elasticity = 1
space.add(body, shape)
return shape
def draw_balls(balls):
for ball in balls:
pos_x = int(ball.body.position.x)
pos_y = int(ball.body.position.y)
pygame.draw.circle(display,(red,green,blue),(pos_x,pos_y),10)
You need to keep track of the old locations of the balls. So for example, every 1 second you add the position of the ball to a list (if the list is too long, lets say above 10, you remove the first item). Then you draw a ball at every position in the list.
Alternatively you could draw the balls to a surface that you never clear. (And then blit that surface to the screen surface) Then the trails of each ball will stay forever.