pub struct Time { /* private fields */ }
Expand description
Frame timing values.
Implementations§
Source§impl Time
impl Time
Sourcepub fn delta_time(&self) -> Duration
pub fn delta_time(&self) -> Duration
Gets the time difference between frames.
Sourcepub fn delta_real_time(&self) -> Duration
pub fn delta_real_time(&self) -> Duration
Gets the time difference between frames ignoring the time speed multiplier.
Sourcepub fn fixed_time(&self) -> Duration
pub fn fixed_time(&self) -> Duration
Gets the fixed time step. Must be used instead of delta_time during fixed updates.
Sourcepub fn frame_number(&self) -> u64
pub fn frame_number(&self) -> u64
Gets the current frame number. This increments by 1 every frame. There is no frame 0.
Sourcepub fn absolute_time(&self) -> Duration
pub fn absolute_time(&self) -> Duration
Gets the time since the start of the game, taking into account the speed multiplier.
Sourcepub fn absolute_real_time(&self) -> Duration
pub fn absolute_real_time(&self) -> Duration
Gets the time since the start of the game, ignoring the speed multiplier.
Sourcepub fn time_scale(&self) -> f32
pub fn time_scale(&self) -> f32
Gets the current time speed multiplier.
Sourcepub fn advance_frame(&mut self, time_diff: Duration)
pub fn advance_frame(&mut self, time_diff: Duration)
Sets delta_time to the given Duration
.
Updates the struct to reflect the changes of this frame.
This should be called before using step_fixed_update.
Examples found in repository?
3fn main() {
4 let mut time = Time::default();
5 time.set_fixed_time(Duration::from_secs_f64(1.0 / 20.0));
6
7 let step = 1.0 / 60.0;
8 for _ in 0..60 {
9 time.advance_frame(Duration::from_secs_f64(step));
10 {} // Run dynamic frame (ie. game logic, rendering)
11 while time.step_fixed_update() {
12 // runs 20 times in a frame.
13 {} // Run fixed frame (ie. physics)
14 }
15 }
16}
Sourcepub fn set_fixed_time(&mut self, time: Duration)
pub fn set_fixed_time(&mut self, time: Duration)
Sets both fixed_time
and fixed_seconds
based on the duration given.
Examples found in repository?
3fn main() {
4 let mut time = Time::default();
5 time.set_fixed_time(Duration::from_secs_f64(1.0 / 20.0));
6
7 let step = 1.0 / 60.0;
8 for _ in 0..60 {
9 time.advance_frame(Duration::from_secs_f64(step));
10 {} // Run dynamic frame (ie. game logic, rendering)
11 while time.step_fixed_update() {
12 // runs 20 times in a frame.
13 {} // Run fixed frame (ie. physics)
14 }
15 }
16}
Sourcepub fn set_time_scale(&mut self, multiplier: f32)
pub fn set_time_scale(&mut self, multiplier: f32)
Sets the time multiplier that affects how time values are computed, effectively slowing or speeding up your game.
§Panics
This will panic if multiplier is NaN, Infinity, or less than 0.
Sourcepub fn step_fixed_update(&mut self) -> bool
pub fn step_fixed_update(&mut self) -> bool
Checks to see if we should perform another fixed update iteration, and if so, returns true and reduces the accumulator.
Examples found in repository?
3fn main() {
4 let mut time = Time::default();
5 time.set_fixed_time(Duration::from_secs_f64(1.0 / 20.0));
6
7 let step = 1.0 / 60.0;
8 for _ in 0..60 {
9 time.advance_frame(Duration::from_secs_f64(step));
10 {} // Run dynamic frame (ie. game logic, rendering)
11 while time.step_fixed_update() {
12 // runs 20 times in a frame.
13 {} // Run fixed frame (ie. physics)
14 }
15 }
16}