I am trying to create a pacman game with pygame but I have run into a few problems. It it saying that the ‘Food’ has no image.
This is my pacman game [code redacted].
The problem is this area here something is wrong and it tells me that food has no attribute image
class Food(pygame.sprite.Sprite):
def __init__(self,x,y,color):
pygame.sprite.Sprite.__init__(self)
pygame.image = pygame.Surface([7,7])
self.image.fill(color)
self.rect = self.image.get_rect()
self.rect.top = y
self.rect.left = x
def update (self,player):
collidePlayer = pygame.sprite.spritecollide(self,player,False)
if collidePlayer:
food.remove
Removing all the irrelevant bits, do you see the difference between the following Sprite subclasses’
__init__methods?The reason you’re getting an error saying that
selfdoesn’t have animageattribute is because you didn’t setself.image, you stored the image in thepygamemodule itself.PS: The lines which look like
seem suspicious to me. If
removeis a method, it’d be called byfood.remove(), andfood.removewouldn’t do anything.