繁殖敌人的精灵

2024-06-01 09:53:17 发布

您现在位置:Python中文网/ 问答频道 /正文

对于我的计算项目,我需要做一些应用程序或游戏。我决定做太空入侵者。我已经设法使基础工作,播放器精灵将产生我可以移动它,背景和音乐工作正常,但现在当我试图创建敌人的精灵,我一直得到这个错误:

C:\Python27\python.exe "C:/Users/Harry/Desktop/Computing Project/Galaxian.py"
Traceback (most recent call last):
  File "C:/Users/Harry/Desktop/Computing Project/Galaxian.py", line 87, in <module>
    mobs.add(Mob)
TypeError: unbound method add() must be called with Mob instance as first argument (got type instance instead)

Process finished with exit code 1

如果有人能帮忙,我会非常感激的!这是我的代码:

^{pr2}$

Tags: 项目instancepyprojectadd应用程序游戏with
1条回答
网友
1楼 · 发布于 2024-06-01 09:53:17
TypeError: unbound method add() must be called with Mob instance as first argument (got type instance instead)

问题是您调用了add方法并传入了类Mob名称,但没有传递Mob的实例。在

^{pr2}$

根据add()的接口,您可能需要执行以下操作:

mob = Mob()
mobs.add(mob)

但这里有点不清楚你想达到什么目的

相关问题 更多 >