Struct bevy_tweening::Tween

source ·
pub struct Tween<T> { /* private fields */ }
Expand description

Single tweening animation instance.

Implementations§

source§

impl<T: 'static> Tween<T>

source

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>

source

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.),
    },
);
source

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);
  }
}
source

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);
});
source

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).

source

pub fn with_direction(self, direction: TweeningDirection) -> Self

Set the playback direction of the tween.

See Tween::set_direction().

source

pub fn direction(&self) -> TweeningDirection

The current animation direction.

See TweeningDirection for details.

source

pub fn with_repeat_count(self, count: impl Into<RepeatCount>) -> Self

Set the number of times to repeat the animation.

source

pub fn with_repeat_strategy(self, strategy: RepeatStrategy) -> Self

Choose how the animation behaves upon a repetition.

source

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.

source

pub fn clear_completed(&mut self)

Clear the callback invoked when the animation completes.

See also set_completed().

source

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.

source

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>

source§

fn from(t: Tween<T>) -> Self

Converts to this type from the input type.
source§

impl<T> Tweenable<T> for Tween<T>

source§

fn duration(&self) -> Duration

Get the duration of a single iteration of the animation. Read more
source§

fn total_duration(&self) -> TotalDuration

Get the total duration of the entire animation, including looping. Read more
source§

fn set_elapsed(&mut self, elapsed: Duration)

Set the current animation playback elapsed time. Read more
source§

fn elapsed(&self) -> Duration

Get the current elapsed duration. Read more
source§

fn tick( &mut self, delta: Duration, target: &mut dyn Targetable<T>, entity: Entity, events: &mut Mut<'_, Events<TweenCompleted>> ) -> TweenState

Tick the animation, advancing it by the given delta time and mutating the given target component or asset. Read more
source§

fn rewind(&mut self)

Rewind the animation to its starting state. Read more
source§

fn set_progress(&mut self, progress: f32)

Set the current animation playback progress. Read more
source§

fn progress(&self) -> f32

Get the current progress in [0:1] of the animation. Read more
source§

fn times_completed(&self) -> u32

Get the number of times this tweenable completed. Read more

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

Return the T [ShaderType] for self. When used in [AsBindGroup] derives, it is safe to assume that all images in self exist.
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for Twhere T: Any,

§

fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for Twhere T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync + 'static>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<T> Event for Twhere T: Send + Sync + 'static,