如何检查bevy Rust的双击
新的是Bevy,需要在我的游戏中实现双击系统,这就是我尝试的。我遇到了一些与包含瞬间的局部变量有关的错误。我已经正确进口了即时板条箱,但不确定Bevy中还需要什么才能使本地VAR工作。
pub fn double_click(
mouse_button_input: Res<Input<MouseButton>>,
mut double_click_time: Local<Instant>,
) {
if mouse_button_input.just_pressed(MouseButton::Left) {
double_click_time = Instant::now();
}
println!("Time: {}", double_click_time.elapsed().as_secs());
}
我遇到的一个错误是在instant :: now();
上,也是
expected struct `bevy::prelude::Local<'_, Instant, >`
found struct `Instant
添加系统的位置,
the trait bound `for<'r, 's> fn(bevy::prelude::Res<'r, bevy::prelude::Input<bevy::prelude::MouseButton>>, bevy::prelude::Local<'s, Instant>) {inventory::double_click}: IntoSystem<(), (), _>` is not satisfied
如果有另一种检测双击的方法,也会给出错误,这也有效!
New to bevy and need to implement a double click system into my game and this is what I tried. I got a couple errors specifically relating to the local variable containing Instant. I have properly imported the instant crate but am not sure what else is needed in bevy to make a local var work.
pub fn double_click(
mouse_button_input: Res<Input<MouseButton>>,
mut double_click_time: Local<Instant>,
) {
if mouse_button_input.just_pressed(MouseButton::Left) {
double_click_time = Instant::now();
}
println!("Time: {}", double_click_time.elapsed().as_secs());
}
One error I am getting is at the Instant::now();
and it is
expected struct `bevy::prelude::Local<'_, Instant, >`
found struct `Instant
Also where the system is added it gives error
the trait bound `for<'r, 's> fn(bevy::prelude::Res<'r, bevy::prelude::Input<bevy::prelude::MouseButton>>, bevy::prelude::Local<'s, Instant>) {inventory::double_click}: IntoSystem<(), (), _>` is not satisfied
If there is another way to detect a double click, that works too!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基于您的错误和
local
的文档(说它实现deref
和derefmut
),您只需要分配给local的 cottents
,这应该解决您的编译错误:我不知道Bevy,所以我不知道这实际上是处理双击的最佳方法。
Based on your error and the docs for
Local
(which say that it implementsDeref
andDerefMut
), you just need to assign to the contents of theLocal
, and that should fix your compile error:I don't know Bevy, so I don't know if this is actually the best way to handle double clicks.
谢谢,这奏效了,但我换句话说,我只是将双击超时施加到用于其他相关事物的全局结构中。
Thanks, that worked but I figured out another way, I just implememnted the double click timeout into a global struct used for a couple other related things.