Module bevy_tween::interpolate
source · Expand description
Module containing some basic built-in interpolator
Plugins:
Built-in interpolators:
§Your own Interpolator
There are a few amount of built-in interpolator because this crate only
implemented the most common ones such as Translation
or
SpriteColor
and some more.
For others, you must implement your own!
Let’s say you’ve created some custom component and you want to interpolate it:
use bevy::prelude::*;
#[derive(Component)]
struct Foo(f32);
You’ll need to create a specific interpolator for this component by:
use bevy_tween::prelude::*;
// First we define an interpolator type for `Foo`.
struct InterpolateFoo {
start: f32,
end: f32,
}
impl Interpolator for InterpolateFoo {
// We define the asscioate type `Item` as the `Foo` component
type Item = Foo;
// Then we define how we want to interpolate `Foo`
fn interpolate(&self, item: &mut Self::Item, value: f32) {
// Usually if the type already have the `.lerp` function provided
// by the `FloatExt` trait then we can use just that
item.0 = self.start.lerp(self.end, value);
}
}
If you’ve created a custom interpolator or a custom component/asset/resource, you may want to register some systems.
While it’s recommended to use the Interpolator
trait, it’s not required
to make your interpolators work in this crate. the Interpolator
as of
currently is only used for registering built-in simple interpolator systems
such as component_tween_system
, resource_tween_system
, and
asset_tween_system
. Its next use is being object-safe for dynamic interpolator.
If you need interpolators with more specific or complex system param, you have to define your own system!
Structs§
Interpolator
forTransform
’s rotation at Z axis. Usually used for 2D rotation.- ColorMaterial
bevy_sprite
- Default dynamic interpolators
- Default interpolators
Interpolator
forTransform
’s scale- SpriteColor
bevy_sprite
Interpolator
forSprite
’s color Interpolator
forTransform
’s translation.
Traits§
Interpolator
is used to specify how to interpolate anSelf::Item
by the implementor.
Functions§
- Constructor for
AngleZ
- Constructor for
AngleZ
that’s relative to previous value using currying. - Constructor for
AngleZ
that’s relative to previous value using currying. - Create boxed closure in order to be used with dynamic
Interpolator
- color_material
bevy_sprite
Constructor forColorMaterial
- color_material_to
bevy_sprite
Constructor forColorMaterial
that’s relative to previous value using currying. - Constructor for
Rotation
- Constructor for
Rotation
that’s relative to previous value using currying. - Constructor for
Rotation
that’s relative to previous value using currying. - Constructor for
Scale
- Constructor for
Scale
that’s relative to previous value using currying. - Constructor for
Scale
that’s relative to previous value using currying. - sprite_color
bevy_sprite
Constructor forSpriteColor
- sprite_color_to
bevy_sprite
Constructor forSpriteColor
that’s relative to previous value using currying. - Constructor for
Translation
- Constructor for
Translation
that’s relative to previous value using currying. - Constructor for
Translation
that’s relative to previous value using currying.
Type Aliases§
- Alias for an
Interpolator
as a boxed trait object.