我已经在其他地方读过类似的问题,但它只是在函数定义中加入'self'。当我检查文件时它是自己的,它实际上已经有了self关键字!这是追溯:
Traceback (most recent call last):
File "C:\Users\Brenda\Documents\The Nick Folder\Mobile Fortress War 3\MFWRT3 - TileClass test\Title.pyw", line 142, in <module>
SelectServer.main()
File "C:\Users\Brenda\Documents\The Nick Folder\Mobile Fortress War 3\MFWRT3 - TileClass test\SelectServer.pyw", line 44, in main
Main.mainloop()
File "C:\Users\Brenda\Documents\The Nick Folder\Mobile Fortress War 3\MFWRT3 - TileClass test\Main.pyw", line 72, in mainloop
globals.alltiles.update()
File "C:\Python32\lib\site-packages\pygame\sprite.py", line 462, in update
s.update(*args)
TypeError: update() takes no arguments (1 given)
我这样称呼它:
globals.alltiles.update()
任何人都可以帮忙吗?
答案 0 :(得分:1)
没有代码来调试它将是一个猜谜游戏,但为了将来参考,精灵组是这样创建的:
#first create a sprite class
class Card(pygame.sprite.Sprite):
def __init__(self,img,pos):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load(os.path.join('img','cards', img))
self.rect = self.image.get_rect()
self.rect.center = pos
#then create a group
mycards = pygame.sprite.Group()
#then add a sprite to the group
holders.add(Card('ace_spade.jpg',coord))
答案 1 :(得分:1)
我有点迟了但可能是因为每张卡的更新方法声明不正确(我假设它是子类化pygame.sprite.Sprite)
应该声明为“def update(self)”而不是“def update()”