<p>见<a href="https://www.pygame.org/docs/ref/sprite.html#pygame.sprite.spritecollide" rel="nofollow noreferrer">^{<cd1>}</a>:</p>
<blockquote>
<p>Return a list containing all Sprites in a Group that intersect with another Sprite.</p>
</blockquote>
<p>因此<code>spritecollide()</code>的参数必须是<a href="https://www.pygame.org/docs/ref/sprite.html#pygame.sprite.Sprite" rel="nofollow noreferrer">^{<cd3>}</a>对象和<a href="https://www.pygame.org/docs/ref/sprite.html#pygame.sprite.Group" rel="nofollow noreferrer">^{<cd4>}</a>对象。<br/>
用<code>pygame.sprite.Sprite</code>对象列表代替<em>组</em>不起作用</p>
<pre class="lang-py prettyprint-override"><code>missileGroup = pygame.sprite.Group()
enemyGroup = pygame.sprite.Group()
</code></pre>
<pre><code>for missile in missileGroup:
if pygame.sprite.spritecollide(missile, enemyGroup, False):
print("Hit")
for enemy in enemyGroup:
if pygame.sprite.spritecollide(enemy, missileGroup, False):
print("HI")
</code></pre>
<hr/>
<p>进一步了解<a href="https://www.pygame.org/docs/ref/sprite.html#pygame.sprite.Sprite.kill" rel="nofollow noreferrer">^{<cd6>}</a></p>
<blockquote>
<p>The Sprite is removed from <strong>all</strong> the Groups that contain it.</p>
</blockquote>
<p>因此,如果在第一个循环中调用<code>kill()</code>,第二个循环将不起作用,因为精灵将从所有组中移除</p>
<p>在<code>reset</code>方法中调用<code>kill()</code><code>missile.reset()</code>分别{<cd11>}导致第二个循环失败</p>