diff --git a/src/lib.rs b/src/lib.rs index 37eaf8b..2f64bd1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -504,12 +504,15 @@ macro_rules! animator_impl { /// Component to control the animation of another component. /// -/// The animated component is the component located on the same entity as the -/// [`Animator`] itself. +/// By default, the animated component is the component located on the same +/// entity as the [`Animator`] itself. But if [`Animator::target`] is set, +/// that entity will be used instead. #[derive(Component)] pub struct Animator { /// Control if this animation is played or not. pub state: AnimatorState, + /// When set, the animated component will be the one located on this entity. + pub target: Option, tweenable: BoxedTweenable, speed: f32, } @@ -529,10 +532,17 @@ impl Animator { Self { state: default(), tweenable: Box::new(tween), + target: None, speed: 1., } } + /// Create a new version of this animator with the `target` set to the given entity. + pub fn with_target(mut self, entity: Entity) -> Self { + self.target = Some(entity); + self + } + animator_impl!(); } diff --git a/src/plugin.rs b/src/plugin.rs index e03e0a7..a409ca0 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -86,14 +86,19 @@ pub enum AnimationSystem { /// attached to the same entity, and tick the animator to animate the component. pub fn component_animator_system( time: Res