diff --git a/examples/custom_skip.rs b/examples/custom_skip.rs index 17d27fe..8847785 100644 --- a/examples/custom_skip.rs +++ b/examples/custom_skip.rs @@ -131,10 +131,7 @@ fn create_scene(mut cmd: Commands, assets: ResMut) { Tween::new( EaseFunction::QuadraticInOut, Duration::from_secs(3), - SplashTextColorLens { - start: Color::WHITE, - end: Color::WHITE.with_a(0.), - }, + SplashTextColorLens::new(vec![Color::WHITE]), ) .with_repeat_count(RepeatCount::Infinite) .with_repeat_strategy(RepeatStrategy::MirroredRepeat), diff --git a/examples/simple.rs b/examples/simple.rs index 77863a7..fbbd5ab 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -43,7 +43,7 @@ fn main() { "Sergio Ribera", TextStyle { font_size: 32., - color: Color::WHITE, + color: Color::BLUE, ..default() }, ), diff --git a/src/lens.rs b/src/lens.rs index 17a9844..32bde73 100644 --- a/src/lens.rs +++ b/src/lens.rs @@ -13,29 +13,31 @@ pub struct SplashImageColorLens { pub end: Color, } -#[derive(Debug, Copy, Clone, PartialEq)] -pub struct SplashTextColorLens { - /// Start color. - pub start: Color, - /// End color. - pub end: Color, -} +#[derive(Debug, Clone, PartialEq)] +/// Lens for interpolating Bevy Text sections. The single parameter is a reference to the color of each section. +pub struct SplashTextColorLens(Vec); -impl InstanceLens for SplashTextColorLens { - fn create(start: Color, end: Color) -> Self { - Self { start, end } +impl SplashTextColorLens { + /// Create instance of Text Lens + /// + /// * `colors`: Each color refers to a section and is placed in order. + pub fn new(colors: Vec) -> Self { + Self(colors) } } impl Lens for SplashTextColorLens { fn lerp(&mut self, target: &mut Text, ratio: f32) { - let start: Vec4 = self.start.into(); - let end: Vec4 = self.end.into(); - let value = start.lerp(end, ratio); target .sections .iter_mut() - .for_each(|section| section.style.color = value.into()); + .enumerate() + .for_each(|(i, section)| { + let start: Vec4 = self.0[i].with_a(0.).into(); + let end: Vec4 = self.0[i].into(); + let value = start.lerp(end, ratio); + section.style.color = value.into(); + }); } } diff --git a/src/splash.rs b/src/splash.rs index d9db2f2..9a9a9a5 100644 --- a/src/splash.rs +++ b/src/splash.rs @@ -111,10 +111,34 @@ pub(crate) fn create_splash( }, ..default() }, - create_animator::( - brand, - max_duration, - i_screen, + Animator::new( + Tween::new( + brand.ease_function, + Duration::from_secs(1), + SplashTextColorLens::new( + text.sections + .iter() + .map(|_| Color::WHITE.with_a(0.)) + .collect(), + ), + ) + .then( + Delay::new(max_duration).then( + Tween::new( + brand.ease_function, + brand.duration, + SplashTextColorLens::new( + text.sections + .iter() + .map(|s| s.style.color) + .collect(), + ), + ) + .with_repeat_strategy(RepeatStrategy::MirroredRepeat) + .with_repeat_count(RepeatCount::Finite(2)) + .with_completed_event(i_screen as u64), + ), + ), ), )) }