擅长:python、mysql、java
<p>似乎您正在使用<code>sprite</code>模块中内置的pygames。(如果我错了,请纠正我)</p>
<p>您可能知道每个精灵都由一个<strong><code>image</code></strong>组成(绘制在一个曲面上)和一个<strong><code>rect</code>对象</strong>(设置位置和大小(!)在<code>image</code>中)。在</p>
<p>正如Luke Taylor建议的那样,您可以在您的<code>player</code>类中创建一个<strong>新的</strong><code>rect</code>对象</p>
<pre><code>self.collideRect = pygame.rect.Rect((0, 0), (32, 150))
</code></pre>
<p>…并将其位置(根据图形)设置为</p>
^{pr2}$
<p>每次你改变<code>player</code>的位置,你也必须调用这一行,所以你的<code>self.collideRect</code>矩形对象在屏幕上随着你的<code>player</code>移动“</em>。在</p>
<p>要测试某个点(例如鼠标坐标)是否在<code>self.collideRect</code>内,请调用</p>
<pre><code>if self.collideRect.collidepoint(x, y) == True:
print("You clicked on me!")
</code></pre>