Python Pygame-如何一次创建多个精灵对象?

Python Pygame-如何一次创建多个精灵对象?,python,Python,我希望能够创建多个汽车精灵对象,但彼此之间的距离不超过x+=10,就像停车场一样。我该怎么办?它不断地在彼此上面产卵。任何帮助都将不胜感激 #class class Car(pygame.sprite.Sprite): def __init__(self): super().__init__() self.image = pygame.image.load('car.png') self.rect = s

我希望能够创建多个汽车精灵对象,但彼此之间的距离不超过x+=10,就像停车场一样。我该怎么办?它不断地在彼此上面产卵。任何帮助都将不胜感激

#class
 class Car(pygame.sprite.Sprite):

        def __init__(self):
            super().__init__()
            self.image = pygame.image.load('car.png')
            self.rect = self.image.get_rect()

    #in my main game to create
        for i in range(3):
            car = Car()
            car.rect.x +=15
            car_sprite_list.add(car)

car.rect.x
可能以
0
开始,因此由于
0+15=15
,所有的汽车将具有相同的
x
坐标。尝试使用
i

car.rect.x = 15 * i