pub struct SpritesheetAnimation {
pub animation_id: AnimationId,
pub playing: bool,
pub speed_factor: f32,
/* private fields */
}
Expand description
A Bevy component that enables spritesheet animations.
It contains an AnimationId that references an Animation created with SpritesheetLibrary::new_animation.
The animation can be paused and resumed by toggling the playing
field.
The speed of the animation can be tweaked with speed_factor
.
§Note
For this component to take effect, the entity must also have a Bevy TextureAtlas component.
§Example
fn my_system(
mut commands: Commands,
mut library: ResMut<SpritesheetLibrary>,
) {
let animation_id = library.new_animation(|animation| {
// ...
});
// ... omitted: load a texture and an atlas layout ...
commands.spawn((
SpriteSheetBundle {
texture: texture.clone(),
atlas: TextureAtlas {
layout: layout.clone(),
..default()
},
..default()
},
SpritesheetAnimation::from_id(animation_id),
));
}
Fields§
§animation_id: AnimationId
The ID of the animation to play
playing: bool
Is the animation currently playing?
The animation can alternatively be stopped by removing the SpritesheetAnimation component from its entity entirely.
However, re-inserting the component at a later stage will restart it from scratch whereas pausing/resuming the animation with playing
keeps its progress.
speed_factor: f32
A speed multiplier for the animation, defaults to 1
Implementations§
source§impl SpritesheetAnimation
impl SpritesheetAnimation
sourcepub fn from_id(animation_id: AnimationId) -> Self
pub fn from_id(animation_id: AnimationId) -> Self
Creates a SpritesheetAnimation component from an AnimationId returned by SpritesheetLibrary::new_animation.
§Arguments
animation_id
- the ID of the animation to play
Trait Implementations§
source§impl Clone for SpritesheetAnimation
impl Clone for SpritesheetAnimation
source§fn clone(&self) -> SpritesheetAnimation
fn clone(&self) -> SpritesheetAnimation
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Component for SpritesheetAnimation
impl Component for SpritesheetAnimation
source§const STORAGE_TYPE: StorageType = bevy::ecs::component::StorageType::Table
const STORAGE_TYPE: StorageType = bevy::ecs::component::StorageType::Table
source§fn register_component_hooks(_hooks: &mut ComponentHooks)
fn register_component_hooks(_hooks: &mut ComponentHooks)
ComponentHooks
.Auto Trait Implementations§
impl Freeze for SpritesheetAnimation
impl RefUnwindSafe for SpritesheetAnimation
impl Send for SpritesheetAnimation
impl Sync for SpritesheetAnimation
impl Unpin for SpritesheetAnimation
impl UnwindSafe for SpritesheetAnimation
Blanket Implementations§
source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut Components, storages: &mut Storages, ids: &mut impl FnMut(ComponentId), )
unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
source§fn get_component_ids(
components: &Components,
ids: &mut impl FnMut(Option<ComponentId>),
)
fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
fn get_components(self, func: &mut impl FnMut(StorageType, OwningPtr<'_>))
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more