pub enum AnimationEvent {
MarkerHit {
entity: Entity,
marker_id: AnimationMarkerId,
animation_id: AnimationId,
animation_repetition: usize,
clip_id: ClipId,
clip_repetition: usize,
},
ClipRepetitionEnd {
entity: Entity,
animation_id: AnimationId,
clip_id: ClipId,
clip_repetition: usize,
},
ClipEnd {
entity: Entity,
animation_id: AnimationId,
clip_id: ClipId,
},
AnimationRepetitionEnd {
entity: Entity,
animation_id: AnimationId,
animation_repetition: usize,
},
AnimationEnd {
entity: Entity,
animation_id: AnimationId,
},
}
Expand description
A Bevy event emitted when an animation reaches a point of interest
- when a clip repetition ends
- when a clip ends (if the clip repeats multiple times, only occurs at the end of the last repetition)
- when an animation repetition ends
- when an animation ends (if the animation repeats multiple times, only occurs at the end of the last repetition)
- 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<AnimationLibrary>
) {
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 = Clip::from_frames([10, 11, 15, 16, 17])
// The character shoots their gun on the fourth frame
.with_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<AnimationLibrary>
) {
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
ClipRepetitionEnd
A repetition of a clip has ended
ClipEnd
An clip ended
AnimationRepetitionEnd
A repetition 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 Event for AnimationEvent
impl Event for AnimationEvent
Source§const AUTO_PROPAGATE: bool = false
const AUTO_PROPAGATE: bool = false
When true, this event will always attempt to propagate when triggered, without requiring a call
to
Trigger::propagate
.Source§type Traversal = ()
type Traversal = ()
The component that describes which Entity to propagate this event to next, when propagation is enabled.
Source§fn register_component_id(world: &mut World) -> ComponentId
fn register_component_id(world: &mut World) -> ComponentId
Generates the
ComponentId
for this event type. Read moreSource§fn component_id(world: &World) -> Option<ComponentId>
fn component_id(world: &World) -> Option<ComponentId>
Fetches the
ComponentId
for this event type,
if it has already been generated. Read moreSource§impl Hash for AnimationEvent
impl Hash for AnimationEvent
Source§impl PartialEq for AnimationEvent
impl PartialEq for AnimationEvent
impl Copy for AnimationEvent
impl Eq 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<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
, which can then be
downcast
into Box<dyn 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>
Converts
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
, which 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)
Converts
&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)
Converts
&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> DowncastSend for T
impl<T> DowncastSend for T
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.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>
Converts
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>
Converts
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