我想不出一种方法来检测玩家是否在 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()):
