首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pygame组更新不需要任何参数

Pygame组更新不需要任何参数
EN

Stack Overflow用户
提问于 2011-10-02 12:23:24
回答 2查看 905关注 0票数 1

我在其他地方也读过类似的问题,但它说只需将'self‘添加到函数定义中。当我检查文件时它是self,它实际上已经有self关键字了!下面是回溯:

代码语言:javascript
复制
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)

我这样称呼它:

代码语言:javascript
复制
globals.alltiles.update()

有人能帮上忙吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-10-13 23:18:16

如果没有要调试的代码,这将是一个猜测游戏,但为了将来的参考,sprite组是这样创建的:

代码语言:javascript
复制
#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
EN

Stack Overflow用户

发布于 2013-05-09 18:57:17

我来晚了一点,但这可能是因为每个卡的更新方法声明不正确(我假设这是pygame.sprite.Sprite的子类化)

它应该声明为"def update(self)“,而不是"def update()”

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7624601

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档