擅长:python、mysql、java
<p>我很久没有在Pygame中做任何事情了,但是IIRC的基本思想是你的精灵应该有一个描述它在屏幕上位置的<code>rect</code><a href="http://www.pygame.org/docs/ref/rect.html" rel="noreferrer">attribute</a>。当您收到鼠标单击事件时,您可以通过调用<code>pygame.mouse.get_pos()</code>来<a href="http://www.pygame.org/docs/ref/mouse.html#pygame.mouse.get_pos" rel="noreferrer">get the position</a>。然后,您可以通过在两个<code>rect</code>对象上调用<code>rect</code>,在以鼠标位置为中心的<code>rect</code>和您的精灵矩形之间<a href="http://www.pygame.org/docs/ref/sprite.html#pygame.sprite.collide_rect" rel="noreferrer">check for a collision</a>。</p>
<p>一个很好的例子是<a href="http://rene.f0o.com/mywiki/LectureFour" rel="noreferrer">here</a>。</p>