Stopwatch
Stopwatch
- elapsed : bevy_utils::Duration
- is_paused : bool
Description
A Stopwatch is a struct that tracks elapsed time when started.
Note that in order to advance the stopwatch
tick
MUST be called.Examples
# use bevy_time::*; use std::time::Duration; let mut stopwatch = Stopwatch::new(); assert_eq!(stopwatch.elapsed_secs(), 0.0); stopwatch.tick(Duration::from_secs_f32(1.0)); // tick one second assert_eq!(stopwatch.elapsed_secs(), 1.0); stopwatch.pause(); stopwatch.tick(Duration::from_secs_f32(1.0)); // paused stopwatches don't tick assert_eq!(stopwatch.elapsed_secs(), 1.0); stopwatch.reset(); // reset the stopwatch assert!(stopwatch.is_paused()); assert_eq!(stopwatch.elapsed_secs(), 0.0);