Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么我的子弹不在pygame程序中移动?_Python_Pygame - Fatal编程技术网

Python 为什么我的子弹不在pygame程序中移动?

Python 为什么我的子弹不在pygame程序中移动?,python,pygame,Python,Pygame,我正在尝试使用pygame用python创建一个简单的2d游戏。这个游戏是外星人入侵的一个残余,在外星人到达屏幕底部之前,一个人会射杀他们。游戏是编译和运行的,但我遇到的问题是关于子弹。他们没有穿过屏幕。问题是在我添加代码让外星人移动后开始的。我试着调整子弹的速度,但没用。下面是我使用的所有模块的要点链接。有没有办法让子弹动起来 这是因为您从未实际调用Bullet对象的update方法 我怀疑您想在update\u bullets函数中执行此操作,因此修复方法如下 def update_bull

我正在尝试使用pygame用python创建一个简单的2d游戏。这个游戏是外星人入侵的一个残余,在外星人到达屏幕底部之前,一个人会射杀他们。游戏是编译和运行的,但我遇到的问题是关于子弹。他们没有穿过屏幕。问题是在我添加代码让外星人移动后开始的。我试着调整子弹的速度,但没用。下面是我使用的所有模块的要点链接。有没有办法让子弹动起来


这是因为您从未实际调用
Bullet
对象的
update
方法

我怀疑您想在
update\u bullets
函数中执行此操作,因此修复方法如下

def update_bullets(aliens, bullets):
    """Update position of bullets and get rid of old bullets."""
   #Check for any bullets that have hit aliens.
   #If so, get rid of the bullet and the alien.
   collisions = pygame.sprite.groupcollide(bullets, aliens, False, True)


    #Get rid of bullets that have disappeared.
    for bullet in bullets.copy():
        bullet.update()
        if bullet.rect.bottom <= 0:
            bullets.remove(bullet)

    print(len(bullets))
def update_项目符号(外星人,项目符号):
“”“更新项目符号的位置并清除旧项目符号。”“”
#检查是否有击中外星人的子弹。
#如果是这样的话,把子弹和外星人扔掉。
碰撞=pygame.sprite.groupcollide(子弹、外星人、假、真)
#扔掉已经消失的子弹。
用于项目符号中的项目符号。复制():
bullet.update()

if bullet.rect.bottom寻求调试帮助的问题(“为什么此代码不工作?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现此问题所需的最短代码。谢谢你,克莱默,成功了!