我试图用pygame创建一个pacman游戏,但是我遇到了一些问题。它说“食物”没有形象。
这是我的pacman游戏[代码编辑]。
问题是这个区域出了点问题,它告诉我食物没有属性图像
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子类的
__init__
方法之间的区别了吗?在出现错误的原因是,
self
没有image
属性,因为您没有设置self.image
,而是将图像存储在pygame
模块中。在PS:看起来像的线条
^{pr2}$我觉得很可疑。如果
remove
是一个方法,它将被food.remove()
调用,food.remove
不会做任何事情。在相关问题 更多 >
编程相关推荐