Struct bevy::core::Stopwatch[]

pub struct Stopwatch { /* fields omitted */ }

A Stopwatch is a struct that track elapsed time when started.

Examples

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.paused());
assert_eq!(stopwatch.elapsed_secs(), 0.0);

Implementations

impl Stopwatch

pub fn new() -> Stopwatch

Create a new unpaused Stopwatch with no elapsed time.

Examples

let stopwatch = Stopwatch::new();
assert_eq!(stopwatch.elapsed_secs(), 0.0);
assert_eq!(stopwatch.paused(), false);

pub fn elapsed(&self) -> Duration

Returns the elapsed time since the last reset of the stopwatch.

Examples

use std::time::Duration;
let mut stopwatch = Stopwatch::new();
stopwatch.tick(Duration::from_secs(1));
assert_eq!(stopwatch.elapsed(), Duration::from_secs(1));

pub fn elapsed_secs(&self) -> f32

pub fn set_elapsed(&mut self, time: Duration)

Sets the elapsed time of the stopwatch.

Examples

use std::time::Duration;
let mut stopwatch = Stopwatch::new();
stopwatch.set_elapsed(Duration::from_secs_f32(1.0));
assert_eq!(stopwatch.elapsed_secs(), 1.0);

pub fn tick(&mut self, delta: Duration) -> &Stopwatch

Advance the stopwatch by delta seconds. If the stopwatch is paused, ticking will not have any effect on elapsed time.

Examples

use std::time::Duration;
let mut stopwatch = Stopwatch::new();
stopwatch.tick(Duration::from_secs_f32(1.5));
assert_eq!(stopwatch.elapsed_secs(), 1.5);

pub fn pause(&mut self)

Pauses the stopwatch. Any call to tick while paused will not have any effect on the elapsed time.

Examples

use std::time::Duration;
let mut stopwatch = Stopwatch::new();
stopwatch.pause();
stopwatch.tick(Duration::from_secs_f32(1.5));
assert!(stopwatch.paused());
assert_eq!(stopwatch.elapsed_secs(), 0.0);

pub fn unpause(&mut self)

Unpauses the stopwatch. Resume the effect of ticking on elapsed time.

Examples

use std::time::Duration;
let mut stopwatch = Stopwatch::new();
stopwatch.pause();
stopwatch.tick(Duration::from_secs_f32(1.0));
stopwatch.unpause();
stopwatch.tick(Duration::from_secs_f32(1.0));
assert!(!stopwatch.paused());
assert_eq!(stopwatch.elapsed_secs(), 1.0);

pub fn paused(&self) -> bool

Returns true if the stopwatch is paused.

Examples

let mut stopwatch = Stopwatch::new();
assert!(!stopwatch.paused());
stopwatch.pause();
assert!(stopwatch.paused());
stopwatch.unpause();
assert!(!stopwatch.paused());

pub fn reset(&mut self)

Resets the stopwatch.

Examples

use std::time::Duration;
let mut stopwatch = Stopwatch::new();
stopwatch.tick(Duration::from_secs_f32(1.5));
stopwatch.reset();
assert_eq!(stopwatch.elapsed_secs(), 0.0);

Trait Implementations

impl Clone for Stopwatch

impl Debug for Stopwatch

impl Default for Stopwatch

impl GetTypeRegistration for Stopwatch

impl Reflect for Stopwatch

impl Struct for Stopwatch

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Any for T where
    T: Any

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> CloneAny for T where
    T: Any + Clone

impl<T> Component for T where
    T: 'static + Send + Sync

impl<T> Downcast for T where
    T: Any

impl<T> Downcast<T> for T

impl<T> DowncastSync for T where
    T: Any + Send + Sync

impl<T> From<T> for T[src]

impl<T> FromWorld for T where
    T: Default

impl<S> GetField for S where
    S: Struct

impl<T> GetPath for T where
    T: Reflect

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> TypeData for T where
    T: 'static + Send + Sync + Clone

impl<T> Upcast<T> for T

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,