Skip to content

Latest commit

 

History

History
28 lines (18 loc) · 1.31 KB

File metadata and controls

28 lines (18 loc) · 1.31 KB

Engine Time

When we start a Bevy app, the underlying timer also starts. We can retrieve the information about the time related to the underlying timer.

In the following example, we retrieve the elapsed time after the App is run. We use this information to move a Circle.

fn circle_moves(time: Res<Time>, mut circles: Query<&mut Transform, With<Handle<ColorMaterial>>>) {
    let mut transform = circles.single_mut();

    *transform = Transform::from_xyz(time.elapsed_seconds().sin() * 200., 0., 0.);
}

We use the resource Time to retrieve the time information. The method elapsed_seconds() of Time returns the seconds passed after the app is run.

Result:

Engine Time

We can use the method elapsed() to customize the unit of the elapsed time.

➡️ Next: A Timer Running Once

📘 Back: Table of contents