Multirious / bevy_tween

Flexible tweening plugin library for Bevy.
Apache License 2.0
87 stars 2 forks source link

Tween by ratio instead of exact seconds #12

Closed musjj closed 4 months ago

musjj commented 4 months ago

It would be nice if you can make a span tween that is based on the ratio of the parent span tweener's duration, rather than exact seconds. For example:

parent
    .spawn(SpanTweenerBundle::new(Duration::from_secs_f32(5.0)))
    .with_children(|parent| {
        let secs = Duration::from_secs_f32;
        parent
            .span_tweens()
            .tween_ratio_exact(
                0.0..0.5,
                EaseFunction::Linear,
                ComponentTween::tweener_parent(interpolate::Scale {
                    start: Vec3::splat(1.0),
                    end: Vec3::splat(2.0),
                }),
            )
            .tween_ratio( // Start from the previous ratio
                1.0,
                EaseFunction::QuadraticInOut,
                ComponentTween::tweener_parent(interpolate::Translation {
                    start: Vec3::splat(0.0),
                    end: Vec3::splat(2.0),
                }),
            );
    });

So here 0.0..0.5 means to tween from the start to 50% of the span tweener's duration (0th second to the 2.5th second in this case).

I think this method would be convenient for quickly and intuitively adjusting the feel of the tween.

musjj commented 4 months ago

I think this is mostly solved, by simply doing this:

let duration = Duration::from_secs_f32(5.0);
let ratio = |rhs| duration.mul_f32(rhs);

Then later on doing something like ratio(0.5)..ratio(0.7), I think this is good enough IMO.