Struct bevy_spritesheet_animation::clip::AnimationClip
source · pub struct AnimationClip { /* private fields */ }
Expand description
An AnimationClip is a reusable sequence of frames. It is the most basic building block for creating animations.
The “frames” of an animation clip actually are TextureAtlas entries, referred to by their indices. At runtime, they will be automatically assigned to our entities’ TextureAtlas component to make things move.
Default parameters like duration, repeat and direction can be specified. The AnimationStages that reference an AnimationClip will inherit its parameters if they don’t specify their own.
An animation clip can also contain markers to identify frames of interest. When an animation reaches such a frame, a MarkerHit event will be emitted. See the documentation of AnimationEvent for more details.
§Example
let spritesheet = Spritesheet::new(8, 4);
let clip_id = library.new_clip(|clip| {
clip
// Use all the frames in row 4
.push_frame_indices(spritesheet.row(4))
// Set a default duration for this clip
.set_default_duration(AnimationDuration::PerCycle(500));
});
// For simple animations, just pass the clip to an animation with into()
let animation1_id = library.new_animation(|animation| {
animation.add_stage(clip_id.into());
});
// If you want more flexibility, explicitly use animation stages
let animation2_id = library.new_animation(|animation| {
// An animation with two stages:
// - clip played once, slowly
// - the same clip played twice, with a higher speed
let mut slow_stage = AnimationStage::from_clip(clip_id);
slow_stage.set_duration(AnimationDuration::PerCycle(500));
let mut fast_stage = AnimationStage::from_clip(clip_id);
fast_stage
.set_duration(AnimationDuration::PerCycle(300))
.set_repeat(2);
animation
.add_stage(slow_stage)
.add_stage(fast_stage);
});
Implementations§
source§impl AnimationClip
impl AnimationClip
sourcepub fn push_frame_indices<I: IntoIterator<Item = usize>>(
&mut self,
indices: I
) -> &mut Self
pub fn push_frame_indices<I: IntoIterator<Item = usize>>( &mut self, indices: I ) -> &mut Self
Pushes new frames into the clip.
§Arguments
indices
: the indices of the frames in the sprite’s texture atlas
§Examples
You can specify frames with raw indices:
let clip_id = library.new_clip(|clip| {
clip.push_frame_indices([0, 1, 7, 8]);
});
Alternatively, you can use a Spritesheet helper:
let spritesheet = Spritesheet::new(3, 4);
let clip_id = library.new_clip(|clip| {
clip.push_frame_indices(spritesheet.row(2));
});
sourcepub fn add_marker(
&mut self,
marker_id: AnimationMarkerId,
frame_index: usize
) -> &mut Self
pub fn add_marker( &mut self, marker_id: AnimationMarkerId, frame_index: usize ) -> &mut Self
Adds a marker to a frame of this clip.
§Arguments
marker_id
- the ID of the markerframe_index
- the index of the frame to attach the marker to
§Example
See the documentation of AnimationEvent for more details.
pub fn markers(&self) -> &HashMap<usize, Vec<AnimationMarkerId>>
pub fn frame_indices(&self) -> &[usize]
pub fn frame_count(&self) -> usize
pub fn set_default_duration(&mut self, duration: AnimationDuration) -> &mut Self
pub fn default_duration(&self) -> &Option<AnimationDuration>
pub fn set_default_repeat(&mut self, repeat: u32) -> &mut Self
pub fn default_repeat(&self) -> &Option<u32>
pub fn set_default_direction( &mut self, direction: AnimationDirection ) -> &mut Self
pub fn default_direction(&self) -> &Option<AnimationDirection>
pub fn set_default_easing(&mut self, easing: Easing) -> &mut Self
pub fn default_easing(&self) -> &Option<Easing>
Trait Implementations§
source§impl Clone for AnimationClip
impl Clone for AnimationClip
source§fn clone(&self) -> AnimationClip
fn clone(&self) -> AnimationClip
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for AnimationClip
impl RefUnwindSafe for AnimationClip
impl Send for AnimationClip
impl Sync for AnimationClip
impl Unpin for AnimationClip
impl UnwindSafe for AnimationClip
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<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.