pub struct SpritesheetAnimation {
pub animation_id: AnimationId,
pub playing: bool,
pub speed_factor: f32,
}
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
§type Storage = TableStorage
type Storage = TableStorage
TableStorage
or SparseStorage
.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<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> 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§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.