【发布时间】:2019-06-11 18:34:13
【问题描述】:
class Snake(pygame.sprite.Sprite):
image: Union[SurfaceType, Any]
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image=pygame.Surface((12,12))
self.image.dill(WHITE)
self.rect=self.image.get_rect()
self.rect.center=(100,100)
self.speedx=0
self.speedy=0
self.score=0
self.tail=[]
class Food(pygame.sprite.Sprite):
def __init__(self,x,y):
pygame.sprite.Sprite.__init__(self)
self.image=pygame.Surface((12,12))
self.image.fill(RED)
self.rect=self.image.get_rect()
self.rect.center=(x,y)
all_sprites=pygame.sprite.Group()
player=Snake()
food=Food(random.randrange(20,width-20),random.randrange(20,height-20))
all_sprites.add(player)
all_sprites.add(food)
错误:
Traceback (most recent call last): File "C:/Users/Asus/Documents/snake.py", line 100, in <module> player=Snake() File "C:/Users/Asus/Documents/snake.py", line 48, in __init__ self.image.dill(WHITE) AttributeError: 'pygame.Surface' object has no attribute 'dill'
【问题讨论】:
-
应该是
self.image.fill吗? pygame.org/docs/ref/surface.html#pygame.Surface.fill -
我建议在 Stack Overflow 上发布之前先阅读错误代码。
标签: python python-3.x pygame pygame-surface