如何检查bevy Rust的双击

发布于 2025-02-10 11:15:49 字数 953 浏览 5 评论 0原文

新的是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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光清浅 2025-02-17 11:15:49

基于您的错误和 local的文档(说它实现derefderefmut),您只需要分配给local的 cottents,这应该解决您的编译错误:

        *double_click_time = Instant::now();

我不知道Bevy,所以我不知道这实际上是处理双击的最佳方法。

Based on your error and the docs for Local (which say that it implements Deref and DerefMut), you just need to assign to the contents of the Local, and that should fix your compile error:

        *double_click_time = Instant::now();

I don't know Bevy, so I don't know if this is actually the best way to handle double clicks.

心凉怎暖 2025-02-17 11:15:49

谢谢,这奏效了,但我换句话说,我只是将双击超时施加到用于其他相关事物的全局结构中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文