Python 当我试图在pygame中发射子弹时,我的游戏崩溃了
我正在做一个游戏,我用左右键移动宇宙飞船,用空格键发射子弹,但按空格键时游戏崩溃了。 我不知道是什么引起的 这是我的密码: 这是错误Python 当我试图在pygame中发射子弹时,我的游戏崩溃了,python,pygame,Python,Pygame,我正在做一个游戏,我用左右键移动宇宙飞船,用空格键发射子弹,但按空格键时游戏崩溃了。 我不知道是什么引起的 这是我的密码: 这是错误 Traceback (most recent call last): File "c:/Users/eidha/OneDrive/سطح المكتب/alien_invasion/alien_invasion.py", line 32, in <module> run_game() File "c:/Users/eidha/OneD
Traceback (most recent call last):
File "c:/Users/eidha/OneDrive/سطح المكتب/alien_invasion/alien_invasion.py", line 32, in <module>
run_game()
File "c:/Users/eidha/OneDrive/سطح المكتب/alien_invasion/alien_invasion.py", line 27, in run_game
gf.check_events(ai_settings, screen, ship, bullets)
File "c:\Users\eidha\OneDrive\سطح المكتب\alien_invasion\game_functions.py", line 34, in
check_events
check_keydown_events(event, ai_settings, screen, ship, bullets)
File "c:\Users\eidha\OneDrive\سطح المكتب\alien_invasion\game_functions.py", line 17, in
check_keydown_events
new_bullet = Bullet(ai_settings, screen, ship)
File "C:\Users\eidha\AppData\Local\Programs\Python\Python37-32\lib\site-
packages\pygame\sprite.py", line 124, in __init__
self.add(*groups)
File "C:\Users\eidha\AppData\Local\Programs\Python\Python37-32\lib\site-
packages\pygame\sprite.py", line 142, in add
self.add(*group)
TypeError: add() argument after * must be an iterable, not Settings
回溯(最近一次呼叫最后一次):
文件“c:/Users/eidha/OneDrive/سطحاكتب/alien_invision/alien_invision.py”,第32行,在
运行游戏()
文件“c:/Users/eidha/OneDrive/سطحالكتب/alien_invision/alien_invision.py”,第27行,在run_游戏中
gf.检查事件(ai设置、屏幕、装运、项目符号)
文件“c:\Users\eidha\OneDrive\سطحالكتب\alien_invision\game_functions.py”,第34行
检查事件
检查按键事件(事件、ai设置、屏幕、发送、项目符号)
文件“c:\Users\eidha\OneDrive\سحالكتب\alien_invision\game_functions.py”,第17行,在
检查按键关闭事件
新建项目符号=项目符号(ai设置、屏幕、发货)
文件“C:\Users\eidha\AppData\Local\Programs\Python\Python37-32\lib\site-
packages\pygame\sprite.py”,第124行,在初始化中__
self.add(*组)
文件“C:\Users\eidha\AppData\Local\Programs\Python\Python37-32\lib\site-
packages\pygame\sprite.py”,添加中第142行
self.add(*组)
TypeError:add()参数在*之后必须是iterable,而不是Settings
项目符号中的\uuuu init\uuuu
函数是大写的,这意味着它不会覆盖默认的精灵组。因此,实际上您正在调用Sprite\uuuu init\uuu
函数,并将ai\u设置(一个设置
对象)作为*组
参数传递
class Bullet(Sprite):
"""A Class To Manage Bullets Fired From The Ship"""
def __init__(self, ai_settings, screen, ship): # Notice lowercase
super().__init__()
...