Skip to main content

Tween

Struct Tween 

Source
pub struct Tween<T: Interpolable + Copy> { /* private fields */ }
Expand description

A generic tween interpolating a value of type T from a start to an end value over a fixed duration, driven by an Easing curve.

Works with any type implementing Interpolable — the engine provides implementations for f64, Vector2D, Vector3D, and Color.

§Why hand-written accessors

Lombok’s Data derive is intentionally not applied here for the same reason as EngineCell: the derive does not propagate generic bounds, so deriving on Tween<T> would force T: Default-style bounds that Interpolable types do not carry. The accessor pairs below follow the same naming contract as the Lombok-generated ones (get_* / set_*).

Implementations§

Source§

impl<T: Interpolable + Copy> Tween<T>

Implements creation, playback control, and value sampling for Tween.

Source

pub fn create(from: T, to: T, duration: f64) -> Tween<T>

Creates a new linear tween from from to to over duration seconds.

The tween starts in the Delayed state only when a delay is later attached via Tween::with_delay; by default it starts Running.

§Arguments
  • T - The start value.
  • T - The end value.
  • f64 - The interpolation duration in seconds.
§Returns
  • Tween<T> - The new tween.
Source

pub fn with_easing(self, easing: Easing) -> Tween<T>

Sets the easing curve, replacing the default Easing::Linear.

§Arguments
  • Easing - The easing curve to apply.
§Returns
  • Tween<T> - The tween, for chaining.
Source

pub fn with_delay(self, delay: f64) -> Tween<T>

Sets a start delay in seconds. While the delay elapses the tween reports its from value and stays in the Delayed state.

§Arguments
  • f64 - The delay in seconds.
§Returns
  • Tween<T> - The tween, for chaining.
Source

pub fn with_mode(self, mode: AnimationMode) -> Tween<T>

Sets the completion mode (Once, Loop, or PingPong), replacing the default AnimationMode::Once.

§Arguments
  • AnimationMode - The completion mode.
§Returns
  • Tween<T> - The tween, for chaining.
Source

pub fn with_on_complete(self, on_complete: Rc<dyn Fn()>) -> Tween<T>

Attaches a callback fired every time the tween completes a cycle (once for Once mode, every wrap for Loop and PingPong).

§Arguments
  • Rc<dyn Fn()> - The completion callback.
§Returns
  • Tween<T> - The tween, for chaining.
Source

pub fn update(&mut self, delta_time: f64) -> T

Advances the tween by the given delta time and returns the current eased value.

Has no effect while the tween is Paused or Finished.

§Arguments
  • f64 - The time elapsed since the last update, in seconds.
§Returns
  • T - The current interpolated value.
Source

pub fn value(&self) -> T

Returns the current interpolated value without advancing time.

§Returns
  • T - The current eased value.
Source

pub fn eased_progress(&self) -> f64

Returns the eased progress of the current cycle in the range 0.0 to 1.0.

§Returns
  • f64 - The eased progress.
Source

pub fn raw_progress(&self) -> f64

Returns the raw (uneased) progress of the current cycle.

§Returns
  • f64 - The raw progress in the range 0.0 to 1.0.
Source

pub fn pause(&mut self)

Pauses the tween.

Source

pub fn resume(&mut self)

Resumes a paused tween.

Source

pub fn reset(&mut self)

Resets the tween to its initial state so it can be replayed.

Source

pub fn is_finished(&self) -> bool

Returns whether the tween has finished (AnimationMode::Once only).

§Returns
  • bool - True if the tween is finished.
Source

pub fn get_state(&self) -> TweenState

Returns the current playback state.

§Returns
  • TweenState - The playback state.
Source

pub fn get_duration(&self) -> f64

Returns the configured duration in seconds.

§Returns
  • f64 - The duration.

Trait Implementations§

Source§

impl<T: Interpolable + Copy> Clone for Tween<T>

Source§

fn clone(&self) -> Tween<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Interpolable + Copy + Debug> Debug for Tween<T>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Interpolable + Copy> Updatable for Tween<T>

Forwards Tween::update through the Updatable trait so tweens can participate in the same generic update loop as entities, animators, scenes, and physics worlds.

Source§

fn update(&mut self, delta_time: f64)

Advance the object’s internal state by the given delta time. 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> !UnwindSafe for Tween<T>

§

impl<T> Freeze for Tween<T>
where T: Freeze,

§

impl<T> Unpin for Tween<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Tween<T>
where T: UnsafeUnpin,

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
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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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

Source§

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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more