pub trait Animation: Sized {
type AsociatedAsset: Asset;
type Query<'w, 's>: QueryData;
// Required methods
fn apply(
animator: &Animator<Self>,
items: &mut <Self::Query<'_, '_> as WorldQuery>::Item<'_>,
asset: &Self::AsociatedAsset,
);
fn spawn(
animation: Option<Self>,
world: &mut World,
path: String,
entity: Entity,
);
fn duration(&self, asset: &Self::AsociatedAsset) -> f32;
}Expand description
Defines an animation and how that animation should update the world every tick. Any type that implements this trait can be given state by
also implementing the AnimationState trait. To spawn an animation, you can use the spawn_animation method on the Commands struct.
Required Associated Types§
Sourcetype AsociatedAsset: Asset
type AsociatedAsset: Asset
The asset that is associated with this animation. For example, aseprite animations are associated with the aseprite asset.
Required Methods§
Sourcefn apply(
animator: &Animator<Self>,
items: &mut <Self::Query<'_, '_> as WorldQuery>::Item<'_>,
asset: &Self::AsociatedAsset,
)
fn apply( animator: &Animator<Self>, items: &mut <Self::Query<'_, '_> as WorldQuery>::Item<'_>, asset: &Self::AsociatedAsset, )
This method defines what the animation should do to the component it is attached to every tick.
Sourcefn spawn(
animation: Option<Self>,
world: &mut World,
path: String,
entity: Entity,
)
fn spawn( animation: Option<Self>, world: &mut World, path: String, entity: Entity, )
Describes how to spawn the animation in the world. This method is used by the spawn_animation method on the Commands struct.
Sourcefn duration(&self, asset: &Self::AsociatedAsset) -> f32
fn duration(&self, asset: &Self::AsociatedAsset) -> f32
Given the state of the animation, should return the duration of the animation in seconds.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.