我想不出一种方法来检测玩家是否在 Pygame 的矩形内单击。我试过了
self.mouserect=(pygame.mouse.get_pos(), 8,8)
后来
if self.click: #(this is true if mouse button is down)
if self.mouserect.colliderect(self.a_thing_to_click_on.rect):
do_stuff
但这给了我一个 AttributeError: 'tuple' object has no attribute 'colliderect'。我做错了什么?
最佳答案
您是否尝试使用 rect.collidepoint()
?
if self.click: #(this is true if mouse button is down)
if self.a_thing_to_click_on.rect.collidepoint(pygame.mouse.get_pos()):
关于python - 测试在 Python 中点击一个矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8444330/