<p>正如模块名“sprite”所提示的那样,函数<code>pygame.sprite.collide_rect</code>和所有其他冲突检测函数期望<code>Sprite</code>实例作为参数</p>
<p>请看<a href="https://www.pygame.org/docs/ref/sprite.html?highlight=group#pygame.sprite.collide_rect" rel="nofollow noreferrer">documentation</a>:</p>
<blockquote>
<p><code>pygame.sprite.collide_rect()</code><br/>
<em>Collision detection between two sprites, using rects.</em><br/>
<code>collide_rect(left, right) -> bool</code></p>
<p>Tests for collision between two sprites. Uses the pygame rect colliderect function to calculate the collision. Intended to be passed as a collided callback function to the *collide functions. Sprites must have a "rect" attributes.</p>
</blockquote>
<p>(另外,通常不直接使用此函数,而是与<a href="https://www.pygame.org/docs/ref/sprite.html#pygame.sprite.Group" rel="nofollow noreferrer">^{<cd3>}</a>一起使用)</p>
<p>因此,要么开始使用<code>Sprite</code>类(这是您应该做的),要么使用<code>Rect</code>类提供的函数,如<a href="https://www.pygame.org/docs/ref/rect.html?highlight=rect#pygame.Rect.colliderect" rel="nofollow noreferrer">^{<cd6>}</a>:</p>
<blockquote>
<p><code>colliderect()</code><br/>
<em>test if two rectangles overlap</em><br/>
<code>colliderect(Rect) -> bool</code></p>
<p>Returns true if any portion of either rectangle overlap (except the top+bottom or left+right edges).</p>
</blockquote>