Python pygame图像属性错误
我试图用pygame创建一个吃豆人游戏,但我遇到了一些问题。它说“食物”没有形象 这是我的pacman游戏[代码编辑] 问题是这个区域出了问题,它告诉我食物没有属性图像Python pygame图像属性错误,python,pygame,Python,Pygame,我试图用pygame创建一个吃豆人游戏,但我遇到了一些问题。它说“食物”没有形象 这是我的pacman游戏[代码编辑] 问题是这个区域出了问题,它告诉我食物没有属性图像 class Food(pygame.sprite.Sprite): def __init__(self,x,y,color): pygame.sprite.Sprite.__init__(self) pygame.image = pygame.Surface([7,7])
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
除去所有不相关的位,您是否看到以下Sprite子类的
\uuuu init\uuu
方法之间的区别
class Wall(pygame.sprite.Sprite):
def __init__(self,x,y,width,height, color):#For when the walls are set up later
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface([width, height]) # <-------------
self.image.fill(color)
class player(pygame.sprite.Sprite):
def __init__ (self,x,y):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface([13,13]) # <-------------
self.image.fill(white)
class Food(pygame.sprite.Sprite)
def __init__(self,x,y,color):
pygame.sprite.Sprite.__init__(self)
pygame.image = pygame.Surface([7,7]) # <----- this one is different!
self.image.fill(color)
对我来说似乎很可疑。如果
remove
是一个方法,它将被food.remove()
调用,而food.remove
不会做任何事情。我没有看到任何地方出现错误。谢谢,我会尝试一下。是的,我很确定应该是食物。移除()但是我还没有时间去检查,但是非常感谢
food.remove