pub enum AnimationEvent {
MarkerHit {
entity: Entity,
marker_id: AnimationMarkerId,
animation_id: AnimationId,
stage_index: usize,
},
ClipCycleEnd {
entity: Entity,
animation_id: AnimationId,
stage_index: usize,
},
ClipEnd {
entity: Entity,
animation_id: AnimationId,
stage_index: usize,
},
AnimationCycleEnd {
entity: Entity,
animation_id: AnimationId,
},
AnimationEnd {
entity: Entity,
animation_id: AnimationId,
},
}
Expand description
A Bevy event emitted when an animation reaches a point of interest
- when a clip cycle ends
- when a clip ends (if the clip repeats multiple times, only occurs at the end of the last cycle)
- when an animation cycle ends
- when an animation ends (if the animation repeats multiple times, only occurs at the end of the last cycle)
- when an animation marker is hit
§Example
You can use those events to be notified of a clip/animation ending.
fn death_transition_system(
mut events: EventReader<AnimationEvent>,
library: Res<SpritesheetLibrary>
) {
for event in events.read() {
match event {
// Some animation just ended...
AnimationEvent::AnimationEnd { animation_id, .. } => {
// ... it was the main character's death animation,
// we can go back to the main menu
if library.is_animation_name(*animation_id, "character dies") {
go_to_main_menu();
}
}
// Ignore other events
_ => (),
}
}
}
§Example
You can also add markers to specific frames of a clip to be notified of an animation reaching points of interest.
// Let's create a marker to be notified when the exact frame
// of the character shooting their gun is played
let marker_id = library.new_marker();
// Naming a marker is not required but it can be convenient to refer to it later
// if you don't want to keep its ID around
library.name_marker(marker_id, "bullet goes out");
let clip_id = library.new_clip(|clip| {
clip
.push_frame_indices([10, 11, 15, 16, 17])
// The character shoots their gun on the fourth frame
.add_marker(marker_id, 3);
});
// We can watch events from any system and react to them
fn spawn_visual_effects_system(
mut events: EventReader<AnimationEvent>,
library: Res<SpritesheetLibrary>
) {
for event in events.read() {
match event {
// Some marker was just hit...
AnimationEvent::MarkerHit { marker_id, .. } => {
// ... it was our "bullet goes out" marker, let's spawn a bullet.
if library.is_marker_name(*marker_id, "bullet goes out") {
spawn_bullet();
}
}
// Ignore other events
_ => (),
}
}
}
Variants§
MarkerHit
An animation marker has been hit
ClipCycleEnd
A cycle of a clip has ended
ClipEnd
An clip ended
AnimationCycleEnd
A cycle of an animation has ended
AnimationEnd
An animation has ended
Trait Implementations§
source§impl Clone for AnimationEvent
impl Clone for AnimationEvent
source§fn clone(&self) -> AnimationEvent
fn clone(&self) -> AnimationEvent
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for AnimationEvent
impl Debug for AnimationEvent
source§impl Hash for AnimationEvent
impl Hash for AnimationEvent
source§impl PartialEq for AnimationEvent
impl PartialEq for AnimationEvent
source§fn eq(&self, other: &AnimationEvent) -> bool
fn eq(&self, other: &AnimationEvent) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl Copy for AnimationEvent
impl Eq for AnimationEvent
impl Event for AnimationEvent
impl StructuralPartialEq for AnimationEvent
Auto Trait Implementations§
impl Freeze for AnimationEvent
impl RefUnwindSafe for AnimationEvent
impl Send for AnimationEvent
impl Sync for AnimationEvent
impl Unpin for AnimationEvent
impl UnwindSafe for AnimationEvent
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
Return the
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
Mutably borrows from an owned value. Read more
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>
Convert
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>
Convert
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)
Convert
&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)
Convert
&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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.