【问题标题】:I'm new to Python. I'm trying to make a simple snake game,but it keeps giving me these errors.(I am using python 3.7.1 and pygame 1.9.6)我是 Python 新手。我正在尝试制作一个简单的蛇游戏,但它一直给我这些错误。(我使用的是 python 3.7.1 和 pygame 1.9.6)
【发布时间】: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'  

【问题讨论】:

标签: python python-3.x pygame pygame-surface


【解决方案1】:

我认为您的意思是“填充”而不是第 7 行的莳萝。

【讨论】:

  • 感谢帮助我去试试
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-13
  • 2020-02-27
  • 2020-08-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多