【发布时间】:2011-11-04 00:40:07
【问题描述】:
我正在使用 Python 进行一个项目,该项目旨在确定一个人的多任务效率。该项目的一部分是让用户使用鼠标响应屏幕上的事件。我决定让用户在一个球内点击。但是,我的代码在验证鼠标光标实际上是否在圆圈范围内时遇到问题。
相关方法的代码如下。圆的半径为 10。
#boolean method to determine if the cursor is within the position of the circle
@classmethod
def is_valid_mouse_click_position(cls, the_ball, mouse_position):
return (mouse_position) == ((range((the_ball.x - 10),(the_ball.x + 10)),
range((the_ball.y + 10), (the_ball.y - 10))))
#method called when a pygame.event.MOUSEBUTTONDOWN is detected.
def handle_mouse_click(self):
print (Ball.is_valid_mouse_click_position(self.the_ball,pygame.mouse.get_pos))
无论我在圆圈内的哪个位置单击,布尔值仍然返回 False。
【问题讨论】:
-
我不确定您如何相信给定的代码会起作用...
-
我不确定您是否真的觉得您的评论对我有用。我对 Python 不太熟悉。
-
这个水平远低于“懂Python”。
标签: python boolean mouseevent pygame