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§

Traits§

Functions§

Type Aliases§