相关疑难解决方法(0)

Pygame鼠标点击检测

我想知道如何编写能够检测鼠标点击精灵的代码.例如:

if #Function that checks for mouse clicked on Sprite:
    print ("You have opened a chest!")
Run Code Online (Sandbox Code Playgroud)

python pygame mouseevent

18
推荐指数
4
解决办法
8万
查看次数

Pygame'LEFT'未定义

我正在做一个游戏.我有pygame导入.我使用的是Python 3.3和Pygame 3.3.始终没有定义相同的错误消息"LEFT".我已经对互联网上的内容进行了精确复制,因为我已经对问题进行了搜索.这是我的代码.我尝试了几种不同的方式,似乎都没有效果.

方法1:

import pygame
event = pygame.event.poll()
if event.type == pygame.MOUSEBUTTONDOWN and event.button == LEFT:
    ....command
Run Code Online (Sandbox Code Playgroud)

方法2 :(基本上全部进入)

from pygame import *
from pygame.locals import *
import pygame
event = pygame.event.poll()
if event.type == MOUSEBUTTONDOWN and event.button == LEFT:
    ......command
Run Code Online (Sandbox Code Playgroud)

在告诉我之前,在这两种方法中我尝试在"LEFT"和"pygame.LEFT"之间切换,依此类推.

有任何想法吗?

非常感谢.

python pygame mouseevent python-3.x

0
推荐指数
1
解决办法
2376
查看次数

标签 统计

mouseevent ×2

pygame ×2

python ×2

python-3.x ×1