Struct bevy_tweening::Tween
source · pub struct Tween<T> { /* private fields */ }
Expand description
Single tweening animation instance.
Implementations§
source§impl<T: 'static> Tween<T>
impl<T: 'static> Tween<T>
sourcepub fn then(self, tween: impl Tweenable<T> + 'static) -> Sequence<T>
pub fn then(self, tween: impl Tweenable<T> + 'static) -> Sequence<T>
Chain another Tweenable
after this tween, making a Sequence
with
the two.
Example
let tween1 = Tween::new(
EaseFunction::QuadraticInOut,
Duration::from_secs(1),
TransformPositionLens {
start: Vec3::ZERO,
end: Vec3::new(3.5, 0., 0.),
},
);
let tween2 = Tween::new(
EaseFunction::QuadraticInOut,
Duration::from_secs(1),
TransformRotationLens {
start: Quat::IDENTITY,
end: Quat::from_rotation_x(90.0_f32.to_radians()),
},
);
let seq = tween1.then(tween2);
source§impl<T> Tween<T>
impl<T> Tween<T>
sourcepub fn new<L>(
ease_function: impl Into<EaseMethod>,
duration: Duration,
lens: L
) -> Selfwhere
L: Lens<T> + Send + Sync + 'static,
pub fn new<L>( ease_function: impl Into<EaseMethod>, duration: Duration, lens: L ) -> Selfwhere L: Lens<T> + Send + Sync + 'static,
Create a new tween animation.
Example
let tween = Tween::new(
EaseFunction::QuadraticInOut,
Duration::from_secs(1),
TransformPositionLens {
start: Vec3::ZERO,
end: Vec3::new(3.5, 0., 0.),
},
);
sourcepub fn with_completed_event(self, user_data: u64) -> Self
pub fn with_completed_event(self, user_data: u64) -> Self
Enable raising a completed event.
If enabled, the tween will raise a TweenCompleted
event when the
animation completed. This is similar to the with_completed()
callback, but uses Bevy events instead.
Example
let tween = Tween::new(
// [...]
)
.with_completed_event(42);
fn my_system(mut reader: EventReader<TweenCompleted>) {
for ev in reader.iter() {
assert_eq!(ev.user_data, 42);
println!("Entity {:?} raised TweenCompleted!", ev.entity);
}
}
sourcepub fn with_completed<C>(self, callback: C) -> Selfwhere
C: Fn(Entity, &Self) + Send + Sync + 'static,
pub fn with_completed<C>(self, callback: C) -> Selfwhere C: Fn(Entity, &Self) + Send + Sync + 'static,
Set a callback invoked when the delay completes.
The callback when invoked receives as parameters the [Entity
] on which
the target and the animator are, as well as a reference to the
current Tween
. This is similar to with_completed_event()
, but
with a callback instead.
Only non-looping tweenables can complete.
Example
let tween = Tween::new(
// [...]
)
.with_completed(|entity, _tween| {
println!("Tween completed on entity {:?}", entity);
});
sourcepub fn set_direction(&mut self, direction: TweeningDirection)
pub fn set_direction(&mut self, direction: TweeningDirection)
Set the playback direction of the tween.
The playback direction influences the mapping of the progress ratio (in
[0:1]) to the actual ratio passed to the lens.
TweeningDirection::Forward
maps the 0
value of progress to the
0
value of the lens ratio. Conversely, TweeningDirection::Backward
reverses the mapping, which effectively makes the tween play reversed,
going from end to start.
Changing the direction doesn’t change any target state, nor any progress
of the tween. Only the direction of animation from this moment
potentially changes. To force a target state change, call
Tweenable::tick()
with a zero delta (Duration::ZERO
).
sourcepub fn with_direction(self, direction: TweeningDirection) -> Self
pub fn with_direction(self, direction: TweeningDirection) -> Self
Set the playback direction of the tween.
sourcepub fn direction(&self) -> TweeningDirection
pub fn direction(&self) -> TweeningDirection
The current animation direction.
See TweeningDirection
for details.
sourcepub fn with_repeat_count(self, count: impl Into<RepeatCount>) -> Self
pub fn with_repeat_count(self, count: impl Into<RepeatCount>) -> Self
Set the number of times to repeat the animation.
sourcepub fn with_repeat_strategy(self, strategy: RepeatStrategy) -> Self
pub fn with_repeat_strategy(self, strategy: RepeatStrategy) -> Self
Choose how the animation behaves upon a repetition.
sourcepub fn set_completed<C>(&mut self, callback: C)where
C: Fn(Entity, &Self) + Send + Sync + 'static,
pub fn set_completed<C>(&mut self, callback: C)where C: Fn(Entity, &Self) + Send + Sync + 'static,
Set a callback invoked when the animation completes.
The callback when invoked receives as parameters the [Entity
] on which
the target and the animator are, as well as a reference to the
current Tween
.
Only non-looping tweenables can complete.
sourcepub fn clear_completed(&mut self)
pub fn clear_completed(&mut self)
Clear the callback invoked when the animation completes.
See also set_completed()
.
sourcepub fn set_completed_event(&mut self, user_data: u64)
pub fn set_completed_event(&mut self, user_data: u64)
Enable or disable raising a completed event.
If enabled, the tween will raise a TweenCompleted
event when the
animation completed. This is similar to the set_completed()
callback, but uses Bevy events instead.
See with_completed_event()
for details.
sourcepub fn clear_completed_event(&mut self)
pub fn clear_completed_event(&mut self)
Clear the event sent when the animation completes.
See also set_completed_event()
.
Trait Implementations§
source§impl<T: 'static> From<Tween<T>> for BoxedTweenable<T>
impl<T: 'static> From<Tween<T>> for BoxedTweenable<T>
source§impl<T> Tweenable<T> for Tween<T>
impl<T> Tweenable<T> for Tween<T>
source§fn duration(&self) -> Duration
fn duration(&self) -> Duration
source§fn total_duration(&self) -> TotalDuration
fn total_duration(&self) -> TotalDuration
source§fn set_elapsed(&mut self, elapsed: Duration)
fn set_elapsed(&mut self, elapsed: Duration)
source§fn tick(
&mut self,
delta: Duration,
target: &mut dyn Targetable<T>,
entity: Entity,
events: &mut Mut<'_, Events<TweenCompleted>>
) -> TweenState
fn tick( &mut self, delta: Duration, target: &mut dyn Targetable<T>, entity: Entity, events: &mut Mut<'_, Events<TweenCompleted>> ) -> TweenState
source§fn set_progress(&mut self, progress: f32)
fn set_progress(&mut self, progress: f32)
source§fn times_completed(&self) -> u32
fn times_completed(&self) -> u32
Auto Trait Implementations§
impl<T> !RefUnwindSafe for Tween<T>
impl<T> Send for Tween<T>
impl<T> Sync for Tween<T>
impl<T> Unpin for Tween<T>
impl<T> !UnwindSafe for Tween<T>
Blanket Implementations§
§impl<T, U> AsBindGroupShaderType<U> for Twhere
U: ShaderType,
&'a T: for<'a> Into<U>,
impl<T, U> AsBindGroupShaderType<U> for Twhere U: ShaderType, &'a T: for<'a> Into<U>,
§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
T
[ShaderType
] for self
. When used in [AsBindGroup
]
derives, it is safe to assume that all images in self
exist.§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.