Trait bevy_tweening::lens::Lens
source · pub trait Lens<T> {
// Required method
fn lerp(&mut self, target: &mut T, ratio: f32);
}
Expand description
A lens over a subset of a component.
The lens takes a target
component or asset from a query, as a mutable
reference, and animates (tweens) a subset of the fields of the
component/asset based on the linear ratio ratio
in [0:1], already
sampled from the easing curve.
§Example
Implement Lens
for a custom type:
struct MyLens {
start: f32,
end: f32,
}
#[derive(Component)]
struct MyStruct(f32);
impl Lens<MyStruct> for MyLens {
fn lerp(&mut self, target: &mut MyStruct, ratio: f32) {
target.0 = self.start + (self.end - self.start) * ratio;
}
}
Required Methods§
sourcefn lerp(&mut self, target: &mut T, ratio: f32)
fn lerp(&mut self, target: &mut T, ratio: f32)
Perform a linear interpolation (lerp) over the subset of fields of a
component or asset the lens focuses on, based on the linear ratio
ratio
. The target
component or asset is mutated in place. The
implementation decides which fields are interpolated, and performs
the animation in-place, overwriting the target.