Skip to main content

Tween

Struct Tween 

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

A tween that interpolates a value from start to end over duration.

The tweened value is stored internally and accessible via value(). You can also use callbacks to react to updates and completion.

§Example

let mut tween = Tween::new(0.0, 100.0, 1.0, Ease::CubicOut);
// In update loop:
tween.update(dt);
let current = tween.value(); // 0.0 → 100.0 over 1 second

Implementations§

Source§

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

Source

pub fn new(start: T, end: T, duration: f32, ease: Ease) -> Self

Create a new tween from start to end over duration seconds.

Source

pub fn with_delay(self, delay: f32) -> Self

Set a delay before the tween starts.

Source

pub fn with_ping_pong(self) -> Self

Set ping-pong mode (tween goes back and forth).

Source

pub fn with_loops(self, loops: u32) -> Self

Set loop count (u32::MAX for infinite).

Source

pub fn with_speed(self, speed: f32) -> Self

Set speed multiplier.

Source

pub fn with_tag(self, tag: &str) -> Self

Set a tag for on-complete identification.

Source

pub fn value(&self) -> T

Get the current interpolated value.

Source

pub fn status(&self) -> TweenStatus

Get the current status.

Source

pub fn progress(&self) -> f32

Get the progress as 0.0–1.0 (accounting for easing).

Source

pub fn reverse(&mut self)

Reverse the tween direction.

Source

pub fn stop(&mut self)

Stop the tween.

Source

pub fn restart(&mut self)

Restart the tween from the beginning.

Source

pub fn update(&mut self, dt: f32) -> bool

Update the tween. Call once per frame with delta time in seconds.

Returns true if the tween just completed this frame.

Trait Implementations§

Source§

impl<T: Clone + Lerp + 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: Debug + Lerp + Copy> Debug for Tween<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

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

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.