mirror of
https://github.com/lisk77/comet.git
synced 2025-10-23 13:38:48 +00:00
feat: added a Timer
component
This commit is contained in:
parent
d3cf390cd8
commit
643c5caf0e
1 changed files with 33 additions and 1 deletions
|
@ -2,7 +2,6 @@
|
|||
// You can use these components as is or as a reference to create your own components
|
||||
// Also just as a nomenclature: bundles are a component made up of multiple components,
|
||||
// so it's a collection of components bundled together (like Transform2D)
|
||||
|
||||
use comet_math::m4;
|
||||
use crate::math::{
|
||||
v2,
|
||||
|
@ -75,6 +74,13 @@ pub struct Color {
|
|||
a: f32
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Timer {
|
||||
time_stack: f32,
|
||||
interval: f32,
|
||||
done: bool
|
||||
}
|
||||
|
||||
// ##################################################
|
||||
// # BUNDLES #
|
||||
// ##################################################
|
||||
|
@ -401,6 +407,10 @@ impl Text {
|
|||
self.color
|
||||
}
|
||||
|
||||
pub fn set_visibility(&mut self, visibility: bool) {
|
||||
self.is_visible = visibility
|
||||
}
|
||||
|
||||
pub fn is_visible(&self) -> bool {
|
||||
self.is_visible
|
||||
}
|
||||
|
@ -465,4 +475,26 @@ impl Color {
|
|||
a: self.a as f64
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Timer {
|
||||
pub fn set_interval(&mut self, interval: f32) {
|
||||
self.interval = interval
|
||||
}
|
||||
|
||||
pub fn update_timer(&mut self, elapsed_time: f32) {
|
||||
self.time_stack += elapsed_time;
|
||||
if self.time_stack > self.interval {
|
||||
self.done = true
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_done(&self) -> bool {
|
||||
self.done
|
||||
}
|
||||
|
||||
pub fn reset(&mut self) {
|
||||
self.time_stack = 0.0;
|
||||
self.done = false;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue