Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why my program doesn't work after launch?

I want to add endless clouds, but my program doesn’t work, what’s wrong?

class Cloud(pygame.sprite.Sprite):
    def __init__(self):
        super(Cloud, self).__init__()
        self.image = clouds_jpg
        self.image.set_colorkey(WHITE1)
        self.rect = self.image.get_rect()
        self.rect.centerx = random.randint(0, WIDTH)
        self.rect.centery = random.randint(HEIGHT - 550, HEIGHT)


    def update(self):
        self.rect.move_ip(-2, 0)
        if self.rect.right <= 0:
            self.rect.left = screen.get_width() 

all_sprites = pygame.sprite.Group()
player = Player()
cloud = Cloud()
all_sprites.add(player, cloud)
...
elif event.type == ADDCLOUD:
            new_cloud = Cloud()
            cloud.add(new_cloud)
            all_sprites.add(new_cloud)

Error:

Traceback (most recent call last): File "C:\Users\дом\My
project\111.py", line 117, in
cloud.add(new_cloud) File "C:\Users\дом\AppData\Local\Programs\Python\Python36\lib\site-packages\pygame\sprite.py",
line 133, in add
self.add(*group) TypeError: add() argument after * must be an iterable, not Cloud

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

cloud is a pygame.sprite.Sprite. You only can add a pygame.sprite.Sprite object toto a pygame.sprite_Group:

clouds = pygame.sprite.Group()
elif event.type == ADDCLOUD:
    new_cloud = Cloud()
    
    # cloud.add(new_cloud)
    clouds.add(new_cloud)

    all_sprites.add(new_cloud)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading