Struct bevy_tweening::Delay

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

A time delay that doesn’t animate anything.

This is generally useful for combining with other tweenables into sequences and tracks, for example to delay the start of a tween in a track relative to another track. The menu example (examples/menu.rs) uses this technique to delay the animation of its buttons.

Implementations§

source§

impl<T: 'static> Delay<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.

source§

impl<T> Delay<T>

source

pub fn new(duration: Duration) -> Self

Create a new Delay with a given duration.

§Panics

Panics if the duration is zero.

source

pub fn with_completed_event(self, user_data: u64) -> Self

Enable raising a completed event.

If enabled, the tweenable will raise a TweenCompleted event when it completed. This is similar to the set_completed() callback, but uses Bevy events instead.

§Example
let delay: Delay<Transform> = Delay::new(Duration::from_secs(5))
  .with_completed_event(42);

fn my_system(mut reader: EventReader<TweenCompleted>) {
  for ev in reader.read() {
    assert_eq!(ev.user_data, 42);
    println!("Entity {:?} raised TweenCompleted!", ev.entity);
  }
}
source

pub fn with_completed<C>(self, callback: C) -> Self
where 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 Delay. 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, delay| {
  println!("Delay of {} seconds elapsed on entity {:?}",
    delay.duration().as_secs(), entity);
});
source

pub fn is_completed(&self) -> bool

Check if the delay completed.

source

pub fn state(&self) -> TweenState

Get the current tweenable state.

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<Delay<T>> for BoxedTweenable<T>

source§

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

Converts to this type from the input type.
source§

impl<T> Tweenable<T> for Delay<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 Delay<T>

§

impl<T> Send for Delay<T>

§

impl<T> Sync for Delay<T>

§

impl<T> Unpin for Delay<T>

§

impl<T> !UnwindSafe for Delay<T>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T, U> AsBindGroupShaderType<U> for T
where 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 T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

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 T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

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>

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 T
where T: Any + Send + Sync,

§

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

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

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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 T
where U: From<T>,

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 T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
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>

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> Settings for T
where T: 'static + Send + Sync,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,