Skip to content

Commit 8e14d99

Browse files
Lenchogjanhohenheimalice-i-cecile
authored
Added finish method for timer (#20154)
# Objective - Add an easy way to finish a Timer ## Solution - Tick the timer by the remaining time ## Testing I have not tested, but it should work --- ## Showcase ```rust let mut timer = Timer::from_seconds(1.5, TimerMode::Once); timer.finish(); assert_eq!(timer.remaining(), Duration::from_secs(0)) ``` --------- Co-authored-by: Jan Hohenheim <jan@hohenheim.ch> Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
1 parent d195116 commit 8e14d99

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

crates/bevy_time/src/timer.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,21 @@ impl Timer {
220220
self.duration = duration;
221221
}
222222

223+
/// Finishes the timer.
224+
///
225+
/// # Examples
226+
/// ```
227+
/// # use bevy_time::*;
228+
/// let mut timer = Timer::from_seconds(1.5, TimerMode::Once);
229+
/// timer.finish();
230+
/// assert!(timer.finished());
231+
/// ```
232+
#[inline]
233+
pub fn finish(&mut self) {
234+
let remaining = self.remaining();
235+
self.tick(remaining);
236+
}
237+
223238
/// Returns the mode of the timer.
224239
///
225240
/// # Examples

0 commit comments

Comments
 (0)