I tried to draw obstacle on screen but got an error in return and now im stuck :/
Here is my obstacle class :
class Obstacle(pygame.sprite.Sprite):
def __init__(self,type):
super().__init__()
if type == 'fly':
self.snail_1 = pygame.image.load("graphics\\snail1.png").convert_alpha()
self.snail_2 = pygame.image.load("graphics\\snail2.png").convert_alpha()
self.snail_frames = [self.snail_1,self.snail_2]
self.snail_index = 0
else:
self.fly_1 = pygame.image.load("graphics\\fly1.png").convert_alpha()
self.fly_2 = pygame.image.load("graphics\\fly2.png").convert_alpha()
self.fly_frames = [self.fly_1, self.fly_2]
self.fly_index = 0
self.rect = self.fly_1.get_rect(midbottom = (200,210))
Here is sprite.Group:
obstacle_group = pygame.sprite.Group()
obstacle_group.add(Obstacle('fly'))
and here is my method to draw:
obstacle_group.draw(screen)
What i'm doing wrong here ?
Traceback (most recent call last): File "C:\Users\Marcin\PycharmProjects\tutorial\main.py", line 105, in <module> obstacle_group.draw(screen) File "C:\Users\Marcin\PycharmProjects\tutorial\venv\lib\site-packages\pygame\sprite.py", line 552, in draw zip(sprites, surface.blits((spr.image, spr.rect) for spr in sprites)) File "C:\Users\Marcin\PycharmProjects\tutorial\venv\lib\site-packages\pygame\sprite.py", line 552, in <genexpr> zip(sprites, surface.blits((spr.image, spr.rect) for spr in sprites)) AttributeError: 'Obstacle' object has no attribute 'image'
Process finished with exit code 1