简体   繁体   English

使用 ursina 进行左点击检测

[英]Left clic detection with ursina

I'm using ursina to make a game, and I want to detect a left click so that I can shoot.我正在使用 ursina 制作游戏,我想检测左键单击以便我可以射击。 So, here's my code :所以,这是我的代码:

def update(self):
    if held_keys['t']:
        print("it works !")

Whenever I press 't', it prints 'it works !', and if I hold it, as long as it's held, the message is printed.每当我按“t”时,它都会打印“它有效!”,如果我按住它,只要按住它,就会打印消息。 Great !伟大的 ! But now, if I try with 'left mouse down' for my key, it doesn't work anymore !但是现在,如果我尝试使用“鼠标左键按下”作为我的键,它就不再起作用了! My code would then be :我的代码将是:

def update(self):
    if held_keys['left mouse down']:
        print("it works !")

So, the problem here is clearly the 'left mouse down' argument.所以,这里的问题显然是“鼠标左键按下”的说法。 But I'm sure it is the correct syntax :但我确定这是正确的语法:

So, the syntax of my argument is correct, my code is correct.所以,我的论点的语法是正确的,我的代码是正确的。 Where is the error located then ?那么错误在哪里? Is there a specific way to handle the mouse, different than the keyboard ?是否有一种特定的方式来处理鼠标,不同于键盘? I really don't think so, that's why I'm kinda confused here.我真的不这么认为,这就是为什么我在这里有点困惑。

The way to debug this would be to print the held_keys dict to see what it contains.调试它的方法是打印held_keys dict 以查看它包含的内容。 The correct name is 'left mouse' .正确的名称是'left mouse' It is that way because the mouse button names are named differently than other keys and are mostly there to make code changes easier.之所以这样是因为鼠标按钮名称的命名与其他键不同,并且主要是为了使代码更改更容易。 Mouse buttons aren't keys after all.毕竟鼠标按钮不是键。

However, what you could do is check mouse.left instead.但是,您可以做的是检查mouse.left

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM