首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Dot Zero调用Rust/Bevy中的计时器?

Dot Zero调用Rust/Bevy中的计时器?
EN

Stack Overflow用户
提问于 2021-11-11 20:36:14
回答 1查看 145关注 0票数 5

在Bevy书中,使用了以下代码:

代码语言:javascript
复制
struct GreetTimer(Timer);

fn greet_people(
    time: Res<Time>, mut timer: ResMut<GreetTimer>, query: Query<&Name, With<Person>>) {
    // update our timer with the time elapsed since the last update
    // if that caused the timer to finish, we say hello to everyone
    if timer.0.tick(time.delta()).just_finished() {
        for name in query.iter() {
            println!("hello {}!", name.0);
        }
    }
}

timer.0name.0调用的作用是什么?这本书没有涉及到它,我看到Timer有一个tick方法,既然timer已经是一个Timer,那么.0在这里做什么呢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-11 20:38:16

它与元组相关。在rust中,可以通过项目位置来访问元组,方法如下:

代码语言:javascript
复制
let foo: (u32, u32) = (0, 1);
println!("{}", foo.0);
println!("{}", foo.1);

一些(元组)结构也会发生这种情况:

代码语言:javascript
复制
struct Foo(u32);

let foo = Foo(1);
println!("{}", foo.0);

Playground

您可以进一步检查一些documentation

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

https://stackoverflow.com/questions/69934627

复制
相关文章

相似问题

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