Tweenable

Trait Tweenable 

Source
pub trait Tweenable: Send + Sync {
    // Required methods
    fn cycle_duration(&self) -> Duration;
    fn total_duration(&self) -> TotalDuration;
    fn set_elapsed(&mut self, elapsed: Duration);
    fn elapsed(&self) -> Duration;
    fn step(
        &mut self,
        tween_id: Entity,
        delta: Duration,
        target: MutUntyped<'_>,
        target_type_id: &TypeId,
        notify_cycle_completed: &mut dyn FnMut(),
    ) -> (TweenState, bool);
    fn rewind(&mut self);
    fn target_type_id(&self) -> Option<TypeId>;

    // Provided methods
    fn cycles_completed(&self) -> u32 { ... }
    fn cycle_fraction(&self) -> f32 { ... }
}
Expand description

Tweening animation description, either a single Tween or a collection of them.

Required Methods§

Source

fn cycle_duration(&self) -> Duration

Get the duration of a single cycle of the animation.

Note that for RepeatStrategy::MirroredRepeat, this is the duration of a single way, either from start to end or back from end to start. The total “loop” duration start -> end -> start to reach back the same state in this case is the double of the cycle duration.

Source

fn total_duration(&self) -> TotalDuration

Get the total duration of the entire animation, including repeating.

For TotalDuration::Finite, this is the number of repeats times the duration of a single cycle (cycle_duration()).

Source

fn set_elapsed(&mut self, elapsed: Duration)

Set the current animation playback elapsed time.

See elapsed() for details on the meaning. For finite durations, if elapsed is greater than or equal to total_duration(), then the animation completes. Animations with infinite duration never complete.

Setting the elapsed time seeks the animation to a new position, but does not apply that change to the underlying component being animated yet. To force the change to apply, call step() with a delta of Duration::ZERO, or wait for it to be automatically called.

Source

fn elapsed(&self) -> Duration

Get the current elapsed duration.

The elapsed duration is the time from the start of the tweening animation. It includes all cycles; if the animation repeats (has more than one cycle), the value can be greater than one cycle_duration(). The value differs depending on whether the animation repeat infinitely or not:

  • For finite repeat counts, including no repeat at all (count = 1), the value is always between 0 and total_duration(). It represents the absolute position over the timeline of all cycles.
  • For infinite repeat, the value loops around after either 1 cycle (for RepeatStrategy::Repeat) or 2 cycles (for RepeatStrategy::MirroredRepeat). The latter is necessary to account for one non-mirrored cycle and one mirrored one.
Source

fn step( &mut self, tween_id: Entity, delta: Duration, target: MutUntyped<'_>, target_type_id: &TypeId, notify_cycle_completed: &mut dyn FnMut(), ) -> (TweenState, bool)

Step the tweenable.

Advance the internal clock of the animation by the specified amount of time. If the animation is currently playing backward (PlaybackDirection::Backward), the clock moves backward and the delta duration is subtracted from the elapsed() time instead of being added to it.

Note that delta = Duration::ZERO is valid, and is sometimes useful to force applying the result of a state change to the underlying animation target.

§Returns

Returns the state of the tweenable after the step.

Source

fn rewind(&mut self)

Rewind the animation to its starting state.

Note that the starting state depends on the current direction. For PlaybackDirection::Forward this is the start point of the lens, whereas for PlaybackDirection::Backward this is the end one.

§Panics

This panics if the current playback direction is PlaybackDirection::Backward and the animation is infinitely repeating.

Source

fn target_type_id(&self) -> Option<TypeId>

Get the TypeId this tweenable targets.

This returns the type of the component or asset that the TweenAnim needs to fetch from the ECS World in order to resolve the animation target.

§Returns

Returns the type of the target, if any, or None if this tweenable is untyped. Typically only Delay is untyped, as this is the only tweenable which doesn’t actually mutate the target, so it doesn’t actually have any target type associated with it.

Provided Methods§

Source

fn cycles_completed(&self) -> u32

Get the number of cycles completed.

For repeating animations, this returns the number of times a single playback cycle was completed. In the case of RepeatStrategy::MirroredRepeat this corresponds to a playback in a single direction, so tweening from start to end and back to start counts as two completed cycles (one forward, one backward).

Source

fn cycle_fraction(&self) -> f32

Get the completion fraction in [0:1] of the current cycle.

Implementors§