python - 测试在 Python 中点击一个矩形

标签 python click pygame

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

相关文章:

python - 第一个输入未插入列表

python - matplotlib x 标签放置

python - 让 Aria2 (aria2c) 恢复通过 RPC 添加的文件的下载

html - 图片下的链接无法点击

jquery - 具有悬停的元素然后单击会删除悬停效果,再次单击会再次添加悬停效果

python - Pygame 向各个方向射击

Python/Pygame字符快速闪烁

python - 自定义 Python 字符映射编解码器

jquery - 是否可以检测 jQuery 单击事件是否已被实际单击或触发器调用?

python - pygame 移动 blitted 文本