Struct bevy_core::Stopwatch[][src]

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[src]

pub fn new() -> Self[src]

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[src]

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[src]

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

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) -> &Self[src]

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)[src]

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)[src]

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[src]

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)[src]

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[src]

impl Debug for Stopwatch[src]

impl Default for Stopwatch[src]

impl GetTypeRegistration for Stopwatch[src]

impl Reflect for Stopwatch[src]

impl Struct for Stopwatch[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

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

impl<T> Downcast for T where
    T: Any

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
[src]

impl<S> GetField for S where
    S: Struct
[src]

impl<T> GetPath for T where
    T: Reflect
[src]

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
[src]

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