首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在bevy中读取鼠标运动?

如何在bevy中读取鼠标运动?
EN

Stack Overflow用户
提问于 2021-04-05 06:54:06
回答 1查看 253关注 0票数 2

我想创建一个第一人称相机。我已经研究了其他几个实现的源代码,比如

https://github.com/mcpar-land/bevy_fly_camera

https://github.com/sburris0/bevy_flycam

但当我自己实现它时(主要是复制粘贴tbh),当在git上使用最新的bevy版本时,它无法编译。

编译输出:

代码语言:javascript
复制
error[E0277]: `*mut (usize, PhantomData<MouseMotion>)` cannot be sent between threads safely
   --> src/player_input.rs:151:13
    |
151 |     mut state: ResMut<State>,
    |                ^^^^^^^^^^^^^ `*mut (usize, PhantomData<MouseMotion>)` cannot be sent between threads safely
    | 
   ::: /home/luca/.cargo/git/checkouts/bevy-f7ffde730c324c74/89a41bc/crates/bevy_ecs/src/resource/resource_query.rs:66:26
    |
66  | pub struct ResMut<'a, T: Resource> {
    |                          -------- required by this bound in `bevy::prelude::ResMut`
    |
    = help: within `player_input::State<'_>`, the trait `Send` is not implemented for `*mut (usize, PhantomData<MouseMotion>)`
    = note: required because it appears within the type `Local<'_, (usize, PhantomData<MouseMotion>)>`
    = note: required because it appears within the type `bevy::prelude::EventReader<'_, MouseMotion>`
    = note: required because it appears within the type `player_input::State<'_>`
    = note: required because of the requirements on the impl of `Resource` for `player_input::State<'_>`

代码如下:

代码语言:javascript
复制
#[derive(Default)]
struct State<'a> {
    mouse_motion_event_reader: EventReader<'a, MouseMotion>,
}

fn mouse_motion_system(
    time: Res<Time>,

    mut state: ResMut<State>, //<-- IMPORTANT LINE (Line 151)

    mouse_motion_events: Res<Events<MouseMotion>>,
    mut query: Query<(&mut FlyCamera, &mut Transform)>,
) {
    //...
}

它仅在最新版本的bevy上抛出此错误,而不在0.4.0版上抛出此错误。

我做错了什么吗?或者我应该在github上打开一个问题,因为这是引擎的错误?

我要怎么做才能让它工作呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-08 03:56:38

在这里,您根本不应该在State中使用EventReader。也许您想要跟踪状态中的最后一个光标位置?

由于在Bevy 0.5中简化了event API,因此只需要将EventReader作为系统参数;mouse_motion_events: Res<Events<MouseMotion>>,现在已经过时,可以用mut mouse_motion_events: EventReader<MouseMotion>替代。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66946558

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档