Skip to main content

Timer

Struct Timer 

Source
pub struct Timer { /* private fields */ }
Expand description

A countdown timer that fires after a fixed duration, optionally repeating.

Timers are updated with the frame delta time; Timer::update returns the number of times the timer fired during that update (0 or 1 for one-shot timers, possibly more for repeating timers after a long frame).

Implementations§

Source§

impl Timer

Implements creation and countdown logic for Timer.

Source

pub fn create(duration: f64) -> Timer

Creates a one-shot timer that fires once after duration seconds.

§Arguments
  • f64 - The countdown duration in seconds.
§Returns
  • Timer - The new one-shot timer.
Source

pub fn create_repeating(duration: f64) -> Timer

Creates a repeating timer that fires every duration seconds.

§Arguments
  • f64 - The interval between firings in seconds.
§Returns
  • Timer - The new repeating timer.
Source

pub fn update(&mut self, delta_time: f64) -> u32

Advances the timer by the given delta time.

§Arguments
  • f64 - The time elapsed since the last update, in seconds.
§Returns
  • u32 - The number of times the timer fired during this update.
Source

pub fn reset(&mut self)

Resets the timer to its initial state so it can count down again.

Source

pub fn pause(&mut self)

Pauses the timer, preserving the accumulated elapsed time.

Source

pub fn resume(&mut self)

Resumes a paused timer.

Source

pub fn is_paused(&self) -> bool

Returns whether the timer is currently paused.

§Returns
  • bool - True if paused.
Source

pub fn is_finished(&self) -> bool

Returns whether a one-shot timer has fired and stopped.

§Returns
  • bool - True if finished.
Source

pub fn progress(&self) -> f64

Returns the countdown progress in the range 0.0 to 1.0.

§Returns
  • f64 - The progress ratio.
Source

pub fn remaining(&self) -> f64

Returns the time remaining until the next firing, in seconds.

§Returns
  • f64 - The remaining time.
Source§

impl Timer

Source

pub fn get_duration(&self) -> f64

Source

pub fn get_mut_duration(&mut self) -> &mut f64

Source

pub fn get_repeating(&self) -> bool

Source

pub fn get_mut_repeating(&mut self) -> &mut bool

Source

pub fn get_paused(&self) -> bool

Source

pub fn get_mut_paused(&mut self) -> &mut bool

Source

pub fn set_paused(&mut self, val: bool) -> &mut Self

Source

pub fn get_finished(&self) -> bool

Source

pub fn get_mut_finished(&mut self) -> &mut bool

Source

pub fn set_finished(&mut self, val: bool) -> &mut Self

Source§

impl Timer

Source

pub fn new(duration: f64, repeating: bool) -> Self

Trait Implementations§

Source§

impl Clone for Timer

Source§

fn clone(&self) -> Timer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Timer

Source§

impl Debug for Timer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Timer

Source§

fn eq(&self, other: &Timer) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Timer

Source§

fn partial_cmp(&self, other: &Timer) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for Timer

Source§

impl Updatable for Timer

Forwards Timer::update through the Updatable trait so timers can participate in the same generic update loop as entities, animators, scenes, and physics worlds.

Source§

fn update(&mut self, delta_time: f64)

Advance the object’s internal state by the given delta time. Read more

Auto Trait Implementations§

§

impl Freeze for Timer

§

impl RefUnwindSafe for Timer

§

impl Send for Timer

§

impl Sync for Timer

§

impl Unpin for Timer

§

impl UnsafeUnpin for Timer

§

impl UnwindSafe for Timer

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more