Struct bevy::animation::AnimationPlayer
pub struct AnimationPlayer { /* private fields */ }
Expand description
Animation controls
Implementations§
§impl AnimationPlayer
impl AnimationPlayer
pub fn start(&mut self, animation: NodeIndex) -> &mut ActiveAnimation
pub fn start(&mut self, animation: NodeIndex) -> &mut ActiveAnimation
Start playing an animation, restarting it if necessary.
pub fn play(&mut self, animation: NodeIndex) -> &mut ActiveAnimation
pub fn play(&mut self, animation: NodeIndex) -> &mut ActiveAnimation
Start playing an animation, unless the requested animation is already playing.
Examples found in repository?
542 543 544 545 546 547 548 549 550 551 552 553
fn play_animations(
mut commands: Commands,
assets: Res<ExampleAssets>,
mut players: Query<(Entity, &mut AnimationPlayer), Without<Handle<AnimationGraph>>>,
) {
for (entity, mut player) in players.iter_mut() {
commands
.entity(entity)
.insert(assets.fox_animation_graph.clone());
player.play(assets.fox_animation_node).repeat();
}
}
More examples
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
fn init_animations(
mut commands: Commands,
mut query: Query<(Entity, &mut AnimationPlayer)>,
animation_graph: Res<ExampleAnimationGraph>,
mut done: Local<bool>,
) {
if *done {
return;
}
for (entity, mut player) in query.iter_mut() {
commands.entity(entity).insert((
animation_graph.0.clone(),
ExampleAnimationWeights::default(),
));
for &node_index in &CLIP_NODE_INDICES {
player.play(node_index.into()).repeat();
}
*done = true;
}
}
/// Read cursor position relative to clip nodes, allowing the user to change weights
/// when dragging the node UI widgets.
fn handle_weight_drag(
mut interaction_query: Query<(&Interaction, &RelativeCursorPosition, &ClipNode)>,
mut animation_weights_query: Query<&mut ExampleAnimationWeights>,
) {
for (interaction, relative_cursor, clip_node) in &mut interaction_query {
if !matches!(*interaction, Interaction::Pressed) {
continue;
}
let Some(pos) = relative_cursor.normalized else {
continue;
};
for mut animation_weights in animation_weights_query.iter_mut() {
animation_weights.weights[clip_node.index] = pos.x.clamp(0., 1.);
}
}
}
// Updates the UI based on the weights that the user has chosen.
fn update_ui(
mut text_query: Query<&mut Text>,
mut background_query: Query<&mut Style, Without<Text>>,
container_query: Query<(&Children, &ClipNode)>,
animation_weights_query: Query<&ExampleAnimationWeights, Changed<ExampleAnimationWeights>>,
) {
for animation_weights in animation_weights_query.iter() {
for (children, clip_node) in &container_query {
// Draw the green background color to visually indicate the weight.
let mut bg_iter = background_query.iter_many_mut(children);
if let Some(mut style) = bg_iter.fetch_next() {
// All nodes are the same width, so `NODE_RECTS[0]` is as good as any other.
style.width =
Val::Px(NODE_RECTS[0].width * animation_weights.weights[clip_node.index]);
}
// Update the node labels with the current weights.
let mut text_iter = text_query.iter_many_mut(children);
if let Some(mut text) = text_iter.fetch_next() {
text.sections[0].value = format!(
"{}\n{:.2}",
clip_node.text, animation_weights.weights[clip_node.index]
);
}
}
}
}
/// Takes the weights that were set in the UI and assigns them to the actual
/// playing animation.
fn sync_weights(mut query: Query<(&mut AnimationPlayer, &ExampleAnimationWeights)>) {
for (mut animation_player, animation_weights) in query.iter_mut() {
for (&animation_node_index, &animation_weight) in CLIP_NODE_INDICES
.iter()
.zip(animation_weights.weights.iter())
{
// If the animation happens to be no longer active, restart it.
if !animation_player.animation_is_playing(animation_node_index.into()) {
animation_player.play(animation_node_index.into());
}
// Set the weight.
if let Some(active_animation) =
animation_player.animation_mut(animation_node_index.into())
{
active_animation.set_weight(animation_weight);
}
}
}
}
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
fn setup_scene_once_loaded(
animations: Res<Animations>,
foxes: Res<Foxes>,
mut commands: Commands,
mut player: Query<(Entity, &mut AnimationPlayer)>,
mut done: Local<bool>,
) {
if !*done && player.iter().len() == foxes.count {
for (entity, mut player) in &mut player {
commands
.entity(entity)
.insert(animations.graph.clone())
.insert(AnimationTransitions::new());
let playing_animation = player.play(animations.node_indices[0]).repeat();
if !foxes.sync {
playing_animation.seek_to(entity.index() as f32 / 10.0);
}
}
*done = true;
}
}
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
fn setup_animations(
mut has_setup: Local<bool>,
mut commands: Commands,
mut players: Query<(Entity, &Name, &mut AnimationPlayer)>,
morph_data: Res<MorphData>,
mut graphs: ResMut<Assets<AnimationGraph>>,
) {
if *has_setup {
return;
}
for (entity, name, mut player) in &mut players {
// The name of the entity in the GLTF scene containing the AnimationPlayer for our morph targets is "Main"
if name.as_str() != "Main" {
continue;
}
let (graph, animation) = AnimationGraph::from_clip(morph_data.the_wave.clone());
commands.entity(entity).insert(graphs.add(graph));
player.play(animation).repeat();
*has_setup = true;
}
}
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
fn assign_clips(
mut players: Query<&mut AnimationPlayer>,
targets: Query<(Entity, &AnimationTarget)>,
parents: Query<&Parent>,
scene_handle: Res<SceneHandle>,
clips: Res<Assets<AnimationClip>>,
gltf_assets: Res<Assets<Gltf>>,
assets: Res<AssetServer>,
mut graphs: ResMut<Assets<AnimationGraph>>,
mut commands: Commands,
mut setup: Local<bool>,
) {
if scene_handle.is_loaded && !*setup {
*setup = true;
} else {
return;
}
let gltf = gltf_assets.get(&scene_handle.gltf_handle).unwrap();
let animations = &gltf.animations;
if animations.is_empty() {
return;
}
let count = animations.len();
let plural = if count == 1 { "" } else { "s" };
info!("Found {} animation{plural}", animations.len());
let names: Vec<_> = gltf.named_animations.keys().collect();
info!("Animation names: {names:?}");
// Map animation target IDs to entities.
let animation_target_id_to_entity: HashMap<_, _> = targets
.iter()
.map(|(entity, target)| (target.id, entity))
.collect();
// Build up a list of all animation clips that belong to each player. A clip
// is considered to belong to an animation player if all targets of the clip
// refer to entities whose nearest ancestor player is that animation player.
let mut player_to_graph: EntityHashMap<(AnimationGraph, Vec<AnimationNodeIndex>)> =
EntityHashMap::default();
for (clip_id, clip) in clips.iter() {
let mut ancestor_player = None;
for target_id in clip.curves().keys() {
// If the animation clip refers to entities that aren't present in
// the scene, bail.
let Some(&target) = animation_target_id_to_entity.get(target_id) else {
continue;
};
// Find the nearest ancestor animation player.
let mut current = Some(target);
while let Some(entity) = current {
if players.contains(entity) {
match ancestor_player {
None => {
// If we haven't found a player yet, record the one
// we found.
ancestor_player = Some(entity);
}
Some(ancestor) => {
// If we have found a player, then make sure it's
// the same player we located before.
if ancestor != entity {
// It's a different player. Bail.
ancestor_player = None;
break;
}
}
}
}
// Go to the next parent.
current = parents.get(entity).ok().map(|parent| parent.get());
}
}
let Some(ancestor_player) = ancestor_player else {
warn!(
"Unexpected animation hierarchy for animation clip {:?}; ignoring.",
clip_id
);
continue;
};
let Some(clip_handle) = assets.get_id_handle(clip_id) else {
warn!("Clip {:?} wasn't loaded.", clip_id);
continue;
};
let &mut (ref mut graph, ref mut clip_indices) =
player_to_graph.entry(ancestor_player).or_default();
let node_index = graph.add_clip(clip_handle, 1.0, graph.root);
clip_indices.push(node_index);
}
// Now that we've built up a list of all clips that belong to each player,
// package them up into a `Clips` component, play the first such animation,
// and add that component to the player.
for (player_entity, (graph, clips)) in player_to_graph {
let Ok(mut player) = players.get_mut(player_entity) else {
warn!("Animation targets referenced a nonexistent player. This shouldn't happen.");
continue;
};
let graph = graphs.add(graph);
let animations = Clips::new(clips);
player.play(animations.current()).repeat();
commands
.entity(player_entity)
.insert(animations)
.insert(graph);
}
}
fn handle_inputs(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut animation_player: Query<(&mut AnimationPlayer, &mut Clips, Entity, Option<&Name>)>,
) {
for (mut player, mut clips, entity, name) in &mut animation_player {
let display_entity_name = match name {
Some(name) => name.to_string(),
None => format!("entity {entity:?}"),
};
if keyboard_input.just_pressed(KeyCode::Space) {
if player.all_paused() {
info!("resuming animations for {display_entity_name}");
player.resume_all();
} else {
info!("pausing animation for {display_entity_name}");
player.pause_all();
}
}
if clips.nodes.len() <= 1 {
continue;
}
if keyboard_input.just_pressed(KeyCode::Enter) {
info!("switching to new animation for {display_entity_name}");
let resume = !player.all_paused();
// set the current animation to its start and pause it to reset to its starting state
player.rewind_all().pause_all();
clips.advance_to_next();
let current_clip = clips.current();
player.play(current_clip).repeat();
if resume {
player.resume_all();
}
}
}
}
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
mut animations: ResMut<Assets<AnimationClip>>,
mut graphs: ResMut<Assets<AnimationGraph>>,
) {
// Camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
// Light
commands.spawn(PointLightBundle {
point_light: PointLight {
intensity: 500_000.0,
..default()
},
transform: Transform::from_xyz(0.0, 2.5, 0.0),
..default()
});
// Let's use the `Name` component to target entities. We can use anything we
// like, but names are convenient.
let planet = Name::new("planet");
let orbit_controller = Name::new("orbit_controller");
let satellite = Name::new("satellite");
// Creating the animation
let mut animation = AnimationClip::default();
// A curve can modify a single part of a transform, here the translation
let planet_animation_target_id = AnimationTargetId::from_name(&planet);
animation.add_curve_to_target(
planet_animation_target_id,
VariableCurve {
keyframe_timestamps: vec![0.0, 1.0, 2.0, 3.0, 4.0],
keyframes: Keyframes::Translation(vec![
Vec3::new(1.0, 0.0, 1.0),
Vec3::new(-1.0, 0.0, 1.0),
Vec3::new(-1.0, 0.0, -1.0),
Vec3::new(1.0, 0.0, -1.0),
// in case seamless looping is wanted, the last keyframe should
// be the same as the first one
Vec3::new(1.0, 0.0, 1.0),
]),
interpolation: Interpolation::Linear,
},
);
// Or it can modify the rotation of the transform.
// To find the entity to modify, the hierarchy will be traversed looking for
// an entity with the right name at each level
let orbit_controller_animation_target_id =
AnimationTargetId::from_names([planet.clone(), orbit_controller.clone()].iter());
animation.add_curve_to_target(
orbit_controller_animation_target_id,
VariableCurve {
keyframe_timestamps: vec![0.0, 1.0, 2.0, 3.0, 4.0],
keyframes: Keyframes::Rotation(vec![
Quat::IDENTITY,
Quat::from_axis_angle(Vec3::Y, PI / 2.),
Quat::from_axis_angle(Vec3::Y, PI / 2. * 2.),
Quat::from_axis_angle(Vec3::Y, PI / 2. * 3.),
Quat::IDENTITY,
]),
interpolation: Interpolation::Linear,
},
);
// If a curve in an animation is shorter than the other, it will not repeat
// until all other curves are finished. In that case, another animation should
// be created for each part that would have a different duration / period
let satellite_animation_target_id = AnimationTargetId::from_names(
[planet.clone(), orbit_controller.clone(), satellite.clone()].iter(),
);
animation.add_curve_to_target(
satellite_animation_target_id,
VariableCurve {
keyframe_timestamps: vec![0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0],
keyframes: Keyframes::Scale(vec![
Vec3::splat(0.8),
Vec3::splat(1.2),
Vec3::splat(0.8),
Vec3::splat(1.2),
Vec3::splat(0.8),
Vec3::splat(1.2),
Vec3::splat(0.8),
Vec3::splat(1.2),
Vec3::splat(0.8),
]),
interpolation: Interpolation::Linear,
},
);
// There can be more than one curve targeting the same entity path
animation.add_curve_to_target(
AnimationTargetId::from_names(
[planet.clone(), orbit_controller.clone(), satellite.clone()].iter(),
),
VariableCurve {
keyframe_timestamps: vec![0.0, 1.0, 2.0, 3.0, 4.0],
keyframes: Keyframes::Rotation(vec![
Quat::IDENTITY,
Quat::from_axis_angle(Vec3::Y, PI / 2.),
Quat::from_axis_angle(Vec3::Y, PI / 2. * 2.),
Quat::from_axis_angle(Vec3::Y, PI / 2. * 3.),
Quat::IDENTITY,
]),
interpolation: Interpolation::Linear,
},
);
// Create the animation graph
let (graph, animation_index) = AnimationGraph::from_clip(animations.add(animation));
// Create the animation player, and set it to repeat
let mut player = AnimationPlayer::default();
player.play(animation_index).repeat();
// Create the scene that will be animated
// First entity is the planet
let planet_entity = commands
.spawn((
PbrBundle {
mesh: meshes.add(Sphere::default()),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
..default()
},
// Add the animation graph and player
planet,
graphs.add(graph),
player,
))
.id();
commands
.entity(planet_entity)
.insert(AnimationTarget {
id: planet_animation_target_id,
player: planet_entity,
})
.with_children(|p| {
// This entity is just used for animation, but doesn't display anything
p.spawn((
SpatialBundle::INHERITED_IDENTITY,
orbit_controller,
AnimationTarget {
id: orbit_controller_animation_target_id,
player: planet_entity,
},
))
.with_children(|p| {
// The satellite, placed at a distance of the planet
p.spawn((
PbrBundle {
transform: Transform::from_xyz(1.5, 0.0, 0.0),
mesh: meshes.add(Cuboid::new(0.5, 0.5, 0.5)),
material: materials.add(Color::srgb(0.3, 0.9, 0.3)),
..default()
},
AnimationTarget {
id: satellite_animation_target_id,
player: planet_entity,
},
satellite,
));
});
});
}
pub fn stop(&mut self, animation: NodeIndex) -> &mut AnimationPlayer
pub fn stop(&mut self, animation: NodeIndex) -> &mut AnimationPlayer
Stops playing the given animation, removing it from the list of playing animations.
pub fn stop_all(&mut self) -> &mut AnimationPlayer
pub fn stop_all(&mut self) -> &mut AnimationPlayer
Stops all currently-playing animations.
pub fn playing_animations(
&self
) -> impl Iterator<Item = (&NodeIndex, &ActiveAnimation)>
pub fn playing_animations( &self ) -> impl Iterator<Item = (&NodeIndex, &ActiveAnimation)>
Iterates through all animations that this AnimationPlayer
is
currently playing.
Examples found in repository?
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
fn keyboard_animation_control(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut animation_players: Query<(&mut AnimationPlayer, &mut AnimationTransitions)>,
animations: Res<Animations>,
mut current_animation: Local<usize>,
) {
for (mut player, mut transitions) in &mut animation_players {
let Some((&playing_animation_index, _)) = player.playing_animations().next() else {
continue;
};
if keyboard_input.just_pressed(KeyCode::Space) {
let playing_animation = player.animation_mut(playing_animation_index).unwrap();
if playing_animation.is_paused() {
playing_animation.resume();
} else {
playing_animation.pause();
}
}
if keyboard_input.just_pressed(KeyCode::ArrowUp) {
let playing_animation = player.animation_mut(playing_animation_index).unwrap();
let speed = playing_animation.speed();
playing_animation.set_speed(speed * 1.2);
}
if keyboard_input.just_pressed(KeyCode::ArrowDown) {
let playing_animation = player.animation_mut(playing_animation_index).unwrap();
let speed = playing_animation.speed();
playing_animation.set_speed(speed * 0.8);
}
if keyboard_input.just_pressed(KeyCode::ArrowLeft) {
let playing_animation = player.animation_mut(playing_animation_index).unwrap();
let elapsed = playing_animation.seek_time();
playing_animation.seek_to(elapsed - 0.1);
}
if keyboard_input.just_pressed(KeyCode::ArrowRight) {
let playing_animation = player.animation_mut(playing_animation_index).unwrap();
let elapsed = playing_animation.seek_time();
playing_animation.seek_to(elapsed + 0.1);
}
if keyboard_input.just_pressed(KeyCode::Enter) {
*current_animation = (*current_animation + 1) % animations.animations.len();
transitions
.play(
&mut player,
animations.animations[*current_animation],
Duration::from_millis(250),
)
.repeat();
}
if keyboard_input.just_pressed(KeyCode::Digit1) {
let playing_animation = player.animation_mut(playing_animation_index).unwrap();
playing_animation
.set_repeat(RepeatAnimation::Count(1))
.replay();
}
if keyboard_input.just_pressed(KeyCode::Digit3) {
let playing_animation = player.animation_mut(playing_animation_index).unwrap();
playing_animation
.set_repeat(RepeatAnimation::Count(3))
.replay();
}
if keyboard_input.just_pressed(KeyCode::Digit5) {
let playing_animation = player.animation_mut(playing_animation_index).unwrap();
playing_animation
.set_repeat(RepeatAnimation::Count(5))
.replay();
}
if keyboard_input.just_pressed(KeyCode::KeyL) {
let playing_animation = player.animation_mut(playing_animation_index).unwrap();
playing_animation.set_repeat(RepeatAnimation::Forever);
}
}
}
pub fn playing_animations_mut(
&mut self
) -> impl Iterator<Item = (&NodeIndex, &mut ActiveAnimation)>
pub fn playing_animations_mut( &mut self ) -> impl Iterator<Item = (&NodeIndex, &mut ActiveAnimation)>
Iterates through all animations that this AnimationPlayer
is
currently playing, mutably.
pub fn is_playing_animation(&self, animation: NodeIndex) -> bool
pub fn is_playing_animation(&self, animation: NodeIndex) -> bool
Check if the given animation node is being played.
pub fn all_finished(&self) -> bool
pub fn all_finished(&self) -> bool
Check if all playing animations have finished, according to the repetition behavior.
pub fn all_paused(&self) -> bool
pub fn all_paused(&self) -> bool
Check if all playing animations are paused.
Examples found in repository?
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
fn handle_inputs(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut animation_player: Query<(&mut AnimationPlayer, &mut Clips, Entity, Option<&Name>)>,
) {
for (mut player, mut clips, entity, name) in &mut animation_player {
let display_entity_name = match name {
Some(name) => name.to_string(),
None => format!("entity {entity:?}"),
};
if keyboard_input.just_pressed(KeyCode::Space) {
if player.all_paused() {
info!("resuming animations for {display_entity_name}");
player.resume_all();
} else {
info!("pausing animation for {display_entity_name}");
player.pause_all();
}
}
if clips.nodes.len() <= 1 {
continue;
}
if keyboard_input.just_pressed(KeyCode::Enter) {
info!("switching to new animation for {display_entity_name}");
let resume = !player.all_paused();
// set the current animation to its start and pause it to reset to its starting state
player.rewind_all().pause_all();
clips.advance_to_next();
let current_clip = clips.current();
player.play(current_clip).repeat();
if resume {
player.resume_all();
}
}
}
}
More examples
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
fn keyboard_animation_control(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut animation_player: Query<(&mut AnimationPlayer, &mut AnimationTransitions)>,
animations: Res<Animations>,
mut current_animation: Local<usize>,
mut foxes: ResMut<Foxes>,
) {
if keyboard_input.just_pressed(KeyCode::Space) {
foxes.moving = !foxes.moving;
}
if keyboard_input.just_pressed(KeyCode::ArrowUp) {
foxes.speed *= 1.25;
}
if keyboard_input.just_pressed(KeyCode::ArrowDown) {
foxes.speed *= 0.8;
}
if keyboard_input.just_pressed(KeyCode::Enter) {
*current_animation = (*current_animation + 1) % animations.node_indices.len();
}
for (mut player, mut transitions) in &mut animation_player {
if keyboard_input.just_pressed(KeyCode::Space) {
if player.all_paused() {
player.resume_all();
} else {
player.pause_all();
}
}
if keyboard_input.just_pressed(KeyCode::ArrowUp) {
player.adjust_speeds(1.25);
}
if keyboard_input.just_pressed(KeyCode::ArrowDown) {
player.adjust_speeds(0.8);
}
if keyboard_input.just_pressed(KeyCode::ArrowLeft) {
player.seek_all_by(-0.1);
}
if keyboard_input.just_pressed(KeyCode::ArrowRight) {
player.seek_all_by(0.1);
}
if keyboard_input.just_pressed(KeyCode::Enter) {
transitions
.play(
&mut player,
animations.node_indices[*current_animation],
Duration::from_millis(250),
)
.repeat();
}
}
}
pub fn pause_all(&mut self) -> &mut AnimationPlayer
pub fn pause_all(&mut self) -> &mut AnimationPlayer
Resume all playing animations.
Examples found in repository?
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
fn handle_inputs(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut animation_player: Query<(&mut AnimationPlayer, &mut Clips, Entity, Option<&Name>)>,
) {
for (mut player, mut clips, entity, name) in &mut animation_player {
let display_entity_name = match name {
Some(name) => name.to_string(),
None => format!("entity {entity:?}"),
};
if keyboard_input.just_pressed(KeyCode::Space) {
if player.all_paused() {
info!("resuming animations for {display_entity_name}");
player.resume_all();
} else {
info!("pausing animation for {display_entity_name}");
player.pause_all();
}
}
if clips.nodes.len() <= 1 {
continue;
}
if keyboard_input.just_pressed(KeyCode::Enter) {
info!("switching to new animation for {display_entity_name}");
let resume = !player.all_paused();
// set the current animation to its start and pause it to reset to its starting state
player.rewind_all().pause_all();
clips.advance_to_next();
let current_clip = clips.current();
player.play(current_clip).repeat();
if resume {
player.resume_all();
}
}
}
}
More examples
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
fn keyboard_animation_control(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut animation_player: Query<(&mut AnimationPlayer, &mut AnimationTransitions)>,
animations: Res<Animations>,
mut current_animation: Local<usize>,
mut foxes: ResMut<Foxes>,
) {
if keyboard_input.just_pressed(KeyCode::Space) {
foxes.moving = !foxes.moving;
}
if keyboard_input.just_pressed(KeyCode::ArrowUp) {
foxes.speed *= 1.25;
}
if keyboard_input.just_pressed(KeyCode::ArrowDown) {
foxes.speed *= 0.8;
}
if keyboard_input.just_pressed(KeyCode::Enter) {
*current_animation = (*current_animation + 1) % animations.node_indices.len();
}
for (mut player, mut transitions) in &mut animation_player {
if keyboard_input.just_pressed(KeyCode::Space) {
if player.all_paused() {
player.resume_all();
} else {
player.pause_all();
}
}
if keyboard_input.just_pressed(KeyCode::ArrowUp) {
player.adjust_speeds(1.25);
}
if keyboard_input.just_pressed(KeyCode::ArrowDown) {
player.adjust_speeds(0.8);
}
if keyboard_input.just_pressed(KeyCode::ArrowLeft) {
player.seek_all_by(-0.1);
}
if keyboard_input.just_pressed(KeyCode::ArrowRight) {
player.seek_all_by(0.1);
}
if keyboard_input.just_pressed(KeyCode::Enter) {
transitions
.play(
&mut player,
animations.node_indices[*current_animation],
Duration::from_millis(250),
)
.repeat();
}
}
}
pub fn resume_all(&mut self) -> &mut AnimationPlayer
pub fn resume_all(&mut self) -> &mut AnimationPlayer
Resume all active animations.
Examples found in repository?
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
fn handle_inputs(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut animation_player: Query<(&mut AnimationPlayer, &mut Clips, Entity, Option<&Name>)>,
) {
for (mut player, mut clips, entity, name) in &mut animation_player {
let display_entity_name = match name {
Some(name) => name.to_string(),
None => format!("entity {entity:?}"),
};
if keyboard_input.just_pressed(KeyCode::Space) {
if player.all_paused() {
info!("resuming animations for {display_entity_name}");
player.resume_all();
} else {
info!("pausing animation for {display_entity_name}");
player.pause_all();
}
}
if clips.nodes.len() <= 1 {
continue;
}
if keyboard_input.just_pressed(KeyCode::Enter) {
info!("switching to new animation for {display_entity_name}");
let resume = !player.all_paused();
// set the current animation to its start and pause it to reset to its starting state
player.rewind_all().pause_all();
clips.advance_to_next();
let current_clip = clips.current();
player.play(current_clip).repeat();
if resume {
player.resume_all();
}
}
}
}
More examples
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
fn keyboard_animation_control(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut animation_player: Query<(&mut AnimationPlayer, &mut AnimationTransitions)>,
animations: Res<Animations>,
mut current_animation: Local<usize>,
mut foxes: ResMut<Foxes>,
) {
if keyboard_input.just_pressed(KeyCode::Space) {
foxes.moving = !foxes.moving;
}
if keyboard_input.just_pressed(KeyCode::ArrowUp) {
foxes.speed *= 1.25;
}
if keyboard_input.just_pressed(KeyCode::ArrowDown) {
foxes.speed *= 0.8;
}
if keyboard_input.just_pressed(KeyCode::Enter) {
*current_animation = (*current_animation + 1) % animations.node_indices.len();
}
for (mut player, mut transitions) in &mut animation_player {
if keyboard_input.just_pressed(KeyCode::Space) {
if player.all_paused() {
player.resume_all();
} else {
player.pause_all();
}
}
if keyboard_input.just_pressed(KeyCode::ArrowUp) {
player.adjust_speeds(1.25);
}
if keyboard_input.just_pressed(KeyCode::ArrowDown) {
player.adjust_speeds(0.8);
}
if keyboard_input.just_pressed(KeyCode::ArrowLeft) {
player.seek_all_by(-0.1);
}
if keyboard_input.just_pressed(KeyCode::ArrowRight) {
player.seek_all_by(0.1);
}
if keyboard_input.just_pressed(KeyCode::Enter) {
transitions
.play(
&mut player,
animations.node_indices[*current_animation],
Duration::from_millis(250),
)
.repeat();
}
}
}
pub fn rewind_all(&mut self) -> &mut AnimationPlayer
pub fn rewind_all(&mut self) -> &mut AnimationPlayer
Rewinds all active animations.
Examples found in repository?
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
fn handle_inputs(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut animation_player: Query<(&mut AnimationPlayer, &mut Clips, Entity, Option<&Name>)>,
) {
for (mut player, mut clips, entity, name) in &mut animation_player {
let display_entity_name = match name {
Some(name) => name.to_string(),
None => format!("entity {entity:?}"),
};
if keyboard_input.just_pressed(KeyCode::Space) {
if player.all_paused() {
info!("resuming animations for {display_entity_name}");
player.resume_all();
} else {
info!("pausing animation for {display_entity_name}");
player.pause_all();
}
}
if clips.nodes.len() <= 1 {
continue;
}
if keyboard_input.just_pressed(KeyCode::Enter) {
info!("switching to new animation for {display_entity_name}");
let resume = !player.all_paused();
// set the current animation to its start and pause it to reset to its starting state
player.rewind_all().pause_all();
clips.advance_to_next();
let current_clip = clips.current();
player.play(current_clip).repeat();
if resume {
player.resume_all();
}
}
}
}
pub fn adjust_speeds(&mut self, factor: f32) -> &mut AnimationPlayer
pub fn adjust_speeds(&mut self, factor: f32) -> &mut AnimationPlayer
Multiplies the speed of all active animations by the given factor.
Examples found in repository?
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
fn keyboard_animation_control(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut animation_player: Query<(&mut AnimationPlayer, &mut AnimationTransitions)>,
animations: Res<Animations>,
mut current_animation: Local<usize>,
mut foxes: ResMut<Foxes>,
) {
if keyboard_input.just_pressed(KeyCode::Space) {
foxes.moving = !foxes.moving;
}
if keyboard_input.just_pressed(KeyCode::ArrowUp) {
foxes.speed *= 1.25;
}
if keyboard_input.just_pressed(KeyCode::ArrowDown) {
foxes.speed *= 0.8;
}
if keyboard_input.just_pressed(KeyCode::Enter) {
*current_animation = (*current_animation + 1) % animations.node_indices.len();
}
for (mut player, mut transitions) in &mut animation_player {
if keyboard_input.just_pressed(KeyCode::Space) {
if player.all_paused() {
player.resume_all();
} else {
player.pause_all();
}
}
if keyboard_input.just_pressed(KeyCode::ArrowUp) {
player.adjust_speeds(1.25);
}
if keyboard_input.just_pressed(KeyCode::ArrowDown) {
player.adjust_speeds(0.8);
}
if keyboard_input.just_pressed(KeyCode::ArrowLeft) {
player.seek_all_by(-0.1);
}
if keyboard_input.just_pressed(KeyCode::ArrowRight) {
player.seek_all_by(0.1);
}
if keyboard_input.just_pressed(KeyCode::Enter) {
transitions
.play(
&mut player,
animations.node_indices[*current_animation],
Duration::from_millis(250),
)
.repeat();
}
}
}
pub fn seek_all_by(&mut self, amount: f32) -> &mut AnimationPlayer
pub fn seek_all_by(&mut self, amount: f32) -> &mut AnimationPlayer
Seeks all active animations forward or backward by the same amount.
To seek forward, pass a positive value; to seek negative, pass a negative value. Values below 0.0 or beyond the end of the animation clip are clamped appropriately.
Examples found in repository?
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
fn keyboard_animation_control(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut animation_player: Query<(&mut AnimationPlayer, &mut AnimationTransitions)>,
animations: Res<Animations>,
mut current_animation: Local<usize>,
mut foxes: ResMut<Foxes>,
) {
if keyboard_input.just_pressed(KeyCode::Space) {
foxes.moving = !foxes.moving;
}
if keyboard_input.just_pressed(KeyCode::ArrowUp) {
foxes.speed *= 1.25;
}
if keyboard_input.just_pressed(KeyCode::ArrowDown) {
foxes.speed *= 0.8;
}
if keyboard_input.just_pressed(KeyCode::Enter) {
*current_animation = (*current_animation + 1) % animations.node_indices.len();
}
for (mut player, mut transitions) in &mut animation_player {
if keyboard_input.just_pressed(KeyCode::Space) {
if player.all_paused() {
player.resume_all();
} else {
player.pause_all();
}
}
if keyboard_input.just_pressed(KeyCode::ArrowUp) {
player.adjust_speeds(1.25);
}
if keyboard_input.just_pressed(KeyCode::ArrowDown) {
player.adjust_speeds(0.8);
}
if keyboard_input.just_pressed(KeyCode::ArrowLeft) {
player.seek_all_by(-0.1);
}
if keyboard_input.just_pressed(KeyCode::ArrowRight) {
player.seek_all_by(0.1);
}
if keyboard_input.just_pressed(KeyCode::Enter) {
transitions
.play(
&mut player,
animations.node_indices[*current_animation],
Duration::from_millis(250),
)
.repeat();
}
}
}
pub fn animation(&self, animation: NodeIndex) -> Option<&ActiveAnimation>
pub fn animation(&self, animation: NodeIndex) -> Option<&ActiveAnimation>
Returns the ActiveAnimation
associated with the given animation
node if it’s currently playing.
If the animation isn’t currently active, returns None
.
pub fn animation_mut(
&mut self,
animation: NodeIndex
) -> Option<&mut ActiveAnimation>
pub fn animation_mut( &mut self, animation: NodeIndex ) -> Option<&mut ActiveAnimation>
Returns a mutable reference to the ActiveAnimation
associated with
the given animation node if it’s currently active.
If the animation isn’t currently active, returns None
.
Examples found in repository?
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
fn sync_weights(mut query: Query<(&mut AnimationPlayer, &ExampleAnimationWeights)>) {
for (mut animation_player, animation_weights) in query.iter_mut() {
for (&animation_node_index, &animation_weight) in CLIP_NODE_INDICES
.iter()
.zip(animation_weights.weights.iter())
{
// If the animation happens to be no longer active, restart it.
if !animation_player.animation_is_playing(animation_node_index.into()) {
animation_player.play(animation_node_index.into());
}
// Set the weight.
if let Some(active_animation) =
animation_player.animation_mut(animation_node_index.into())
{
active_animation.set_weight(animation_weight);
}
}
}
}
More examples
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
fn keyboard_animation_control(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut animation_players: Query<(&mut AnimationPlayer, &mut AnimationTransitions)>,
animations: Res<Animations>,
mut current_animation: Local<usize>,
) {
for (mut player, mut transitions) in &mut animation_players {
let Some((&playing_animation_index, _)) = player.playing_animations().next() else {
continue;
};
if keyboard_input.just_pressed(KeyCode::Space) {
let playing_animation = player.animation_mut(playing_animation_index).unwrap();
if playing_animation.is_paused() {
playing_animation.resume();
} else {
playing_animation.pause();
}
}
if keyboard_input.just_pressed(KeyCode::ArrowUp) {
let playing_animation = player.animation_mut(playing_animation_index).unwrap();
let speed = playing_animation.speed();
playing_animation.set_speed(speed * 1.2);
}
if keyboard_input.just_pressed(KeyCode::ArrowDown) {
let playing_animation = player.animation_mut(playing_animation_index).unwrap();
let speed = playing_animation.speed();
playing_animation.set_speed(speed * 0.8);
}
if keyboard_input.just_pressed(KeyCode::ArrowLeft) {
let playing_animation = player.animation_mut(playing_animation_index).unwrap();
let elapsed = playing_animation.seek_time();
playing_animation.seek_to(elapsed - 0.1);
}
if keyboard_input.just_pressed(KeyCode::ArrowRight) {
let playing_animation = player.animation_mut(playing_animation_index).unwrap();
let elapsed = playing_animation.seek_time();
playing_animation.seek_to(elapsed + 0.1);
}
if keyboard_input.just_pressed(KeyCode::Enter) {
*current_animation = (*current_animation + 1) % animations.animations.len();
transitions
.play(
&mut player,
animations.animations[*current_animation],
Duration::from_millis(250),
)
.repeat();
}
if keyboard_input.just_pressed(KeyCode::Digit1) {
let playing_animation = player.animation_mut(playing_animation_index).unwrap();
playing_animation
.set_repeat(RepeatAnimation::Count(1))
.replay();
}
if keyboard_input.just_pressed(KeyCode::Digit3) {
let playing_animation = player.animation_mut(playing_animation_index).unwrap();
playing_animation
.set_repeat(RepeatAnimation::Count(3))
.replay();
}
if keyboard_input.just_pressed(KeyCode::Digit5) {
let playing_animation = player.animation_mut(playing_animation_index).unwrap();
playing_animation
.set_repeat(RepeatAnimation::Count(5))
.replay();
}
if keyboard_input.just_pressed(KeyCode::KeyL) {
let playing_animation = player.animation_mut(playing_animation_index).unwrap();
playing_animation.set_repeat(RepeatAnimation::Forever);
}
}
}
pub fn animation_is_playing(&self, animation: NodeIndex) -> bool
pub fn animation_is_playing(&self, animation: NodeIndex) -> bool
Returns true if the animation is currently playing or paused, or false if the animation is stopped.
Examples found in repository?
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
fn sync_weights(mut query: Query<(&mut AnimationPlayer, &ExampleAnimationWeights)>) {
for (mut animation_player, animation_weights) in query.iter_mut() {
for (&animation_node_index, &animation_weight) in CLIP_NODE_INDICES
.iter()
.zip(animation_weights.weights.iter())
{
// If the animation happens to be no longer active, restart it.
if !animation_player.animation_is_playing(animation_node_index.into()) {
animation_player.play(animation_node_index.into());
}
// Set the weight.
if let Some(active_animation) =
animation_player.animation_mut(animation_node_index.into())
{
active_animation.set_weight(animation_weight);
}
}
}
}
Trait Implementations§
§impl Component for AnimationPlayer
impl Component for AnimationPlayer
§const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table
const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table
§fn register_component_hooks(_hooks: &mut ComponentHooks)
fn register_component_hooks(_hooks: &mut ComponentHooks)
ComponentHooks
.§impl Default for AnimationPlayer
impl Default for AnimationPlayer
§fn default() -> AnimationPlayer
fn default() -> AnimationPlayer
§impl FromReflect for AnimationPlayerwhere
AnimationPlayer: Any + Send + Sync,
BTreeMap<NodeIndex, ActiveAnimation>: FromReflect + TypePath + RegisterForReflection,
HashMap<NodeIndex, f32>: FromReflect + TypePath + RegisterForReflection,
impl FromReflect for AnimationPlayerwhere
AnimationPlayer: Any + Send + Sync,
BTreeMap<NodeIndex, ActiveAnimation>: FromReflect + TypePath + RegisterForReflection,
HashMap<NodeIndex, f32>: FromReflect + TypePath + RegisterForReflection,
§fn from_reflect(reflect: &(dyn Reflect + 'static)) -> Option<AnimationPlayer>
fn from_reflect(reflect: &(dyn Reflect + 'static)) -> Option<AnimationPlayer>
Self
from a reflected value.§fn take_from_reflect(
reflect: Box<dyn Reflect>
) -> Result<Self, Box<dyn Reflect>>
fn take_from_reflect( reflect: Box<dyn Reflect> ) -> Result<Self, Box<dyn Reflect>>
Self
using,
constructing the value using from_reflect
if that fails. Read more§impl GetTypeRegistration for AnimationPlayerwhere
AnimationPlayer: Any + Send + Sync,
BTreeMap<NodeIndex, ActiveAnimation>: FromReflect + TypePath + RegisterForReflection,
HashMap<NodeIndex, f32>: FromReflect + TypePath + RegisterForReflection,
impl GetTypeRegistration for AnimationPlayerwhere
AnimationPlayer: Any + Send + Sync,
BTreeMap<NodeIndex, ActiveAnimation>: FromReflect + TypePath + RegisterForReflection,
HashMap<NodeIndex, f32>: FromReflect + TypePath + RegisterForReflection,
§fn get_type_registration() -> TypeRegistration
fn get_type_registration() -> TypeRegistration
TypeRegistration
for this type.§fn register_type_dependencies(registry: &mut TypeRegistry)
fn register_type_dependencies(registry: &mut TypeRegistry)
§impl Reflect for AnimationPlayerwhere
AnimationPlayer: Any + Send + Sync,
BTreeMap<NodeIndex, ActiveAnimation>: FromReflect + TypePath + RegisterForReflection,
HashMap<NodeIndex, f32>: FromReflect + TypePath + RegisterForReflection,
impl Reflect for AnimationPlayerwhere
AnimationPlayer: Any + Send + Sync,
BTreeMap<NodeIndex, ActiveAnimation>: FromReflect + TypePath + RegisterForReflection,
HashMap<NodeIndex, f32>: FromReflect + TypePath + RegisterForReflection,
§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
§fn into_any(self: Box<AnimationPlayer>) -> Box<dyn Any>
fn into_any(self: Box<AnimationPlayer>) -> Box<dyn Any>
Box<dyn Any>
.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut dyn Any
.§fn into_reflect(self: Box<AnimationPlayer>) -> Box<dyn Reflect>
fn into_reflect(self: Box<AnimationPlayer>) -> Box<dyn Reflect>
§fn as_reflect(&self) -> &(dyn Reflect + 'static)
fn as_reflect(&self) -> &(dyn Reflect + 'static)
§fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
§fn clone_value(&self) -> Box<dyn Reflect>
fn clone_value(&self) -> Box<dyn Reflect>
Reflect
trait object. Read more§fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>
§fn apply(&mut self, value: &(dyn Reflect + 'static))
fn apply(&mut self, value: &(dyn Reflect + 'static))
§fn reflect_kind(&self) -> ReflectKind
fn reflect_kind(&self) -> ReflectKind
§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
§fn reflect_owned(self: Box<AnimationPlayer>) -> ReflectOwned
fn reflect_owned(self: Box<AnimationPlayer>) -> ReflectOwned
§fn reflect_partial_eq(&self, value: &(dyn Reflect + 'static)) -> Option<bool>
fn reflect_partial_eq(&self, value: &(dyn Reflect + 'static)) -> Option<bool>
§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
§fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
§fn serializable(&self) -> Option<Serializable<'_>>
fn serializable(&self) -> Option<Serializable<'_>>
§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
§impl Struct for AnimationPlayerwhere
AnimationPlayer: Any + Send + Sync,
BTreeMap<NodeIndex, ActiveAnimation>: FromReflect + TypePath + RegisterForReflection,
HashMap<NodeIndex, f32>: FromReflect + TypePath + RegisterForReflection,
impl Struct for AnimationPlayerwhere
AnimationPlayer: Any + Send + Sync,
BTreeMap<NodeIndex, ActiveAnimation>: FromReflect + TypePath + RegisterForReflection,
HashMap<NodeIndex, f32>: FromReflect + TypePath + RegisterForReflection,
§fn field(&self, name: &str) -> Option<&(dyn Reflect + 'static)>
fn field(&self, name: &str) -> Option<&(dyn Reflect + 'static)>
name
as a &dyn Reflect
.§fn field_mut(&mut self, name: &str) -> Option<&mut (dyn Reflect + 'static)>
fn field_mut(&mut self, name: &str) -> Option<&mut (dyn Reflect + 'static)>
name
as a
&mut dyn Reflect
.§fn field_at(&self, index: usize) -> Option<&(dyn Reflect + 'static)>
fn field_at(&self, index: usize) -> Option<&(dyn Reflect + 'static)>
index
as a
&dyn Reflect
.§fn field_at_mut(&mut self, index: usize) -> Option<&mut (dyn Reflect + 'static)>
fn field_at_mut(&mut self, index: usize) -> Option<&mut (dyn Reflect + 'static)>
index
as a &mut dyn Reflect
.§fn iter_fields(&self) -> FieldIter<'_> ⓘ
fn iter_fields(&self) -> FieldIter<'_> ⓘ
§fn clone_dynamic(&self) -> DynamicStruct
fn clone_dynamic(&self) -> DynamicStruct
DynamicStruct
.§impl TypePath for AnimationPlayer
impl TypePath for AnimationPlayer
§fn short_type_path() -> &'static str
fn short_type_path() -> &'static str
§fn type_ident() -> Option<&'static str>
fn type_ident() -> Option<&'static str>
§fn crate_name() -> Option<&'static str>
fn crate_name() -> Option<&'static str>
§impl Typed for AnimationPlayerwhere
AnimationPlayer: Any + Send + Sync,
BTreeMap<NodeIndex, ActiveAnimation>: FromReflect + TypePath + RegisterForReflection,
HashMap<NodeIndex, f32>: FromReflect + TypePath + RegisterForReflection,
impl Typed for AnimationPlayerwhere
AnimationPlayer: Any + Send + Sync,
BTreeMap<NodeIndex, ActiveAnimation>: FromReflect + TypePath + RegisterForReflection,
HashMap<NodeIndex, f32>: FromReflect + TypePath + RegisterForReflection,
Auto Trait Implementations§
impl Freeze for AnimationPlayer
impl RefUnwindSafe for AnimationPlayer
impl Send for AnimationPlayer
impl Sync for AnimationPlayer
impl Unpin for AnimationPlayer
impl UnwindSafe for AnimationPlayer
Blanket Implementations§
§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
§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
§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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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
.§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
.§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.§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.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
fn get_components(self, func: &mut impl FnMut(StorageType, OwningPtr<'_>))
§impl<T> DynamicTypePath for Twhere
T: TypePath,
impl<T> DynamicTypePath for Twhere
T: TypePath,
§fn reflect_type_path(&self) -> &str
fn reflect_type_path(&self) -> &str
TypePath::type_path
.§fn reflect_short_type_path(&self) -> &str
fn reflect_short_type_path(&self) -> &str
§fn reflect_type_ident(&self) -> Option<&str>
fn reflect_type_ident(&self) -> Option<&str>
TypePath::type_ident
.§fn reflect_crate_name(&self) -> Option<&str>
fn reflect_crate_name(&self) -> Option<&str>
TypePath::crate_name
.§fn reflect_module_path(&self) -> Option<&str>
fn reflect_module_path(&self) -> Option<&str>
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self
using data from the given World
.§impl<T> GetPath for T
impl<T> GetPath for T
§fn reflect_path<'p>(
&self,
path: impl ReflectPath<'p>
) -> Result<&(dyn Reflect + 'static), ReflectPathError<'p>>
fn reflect_path<'p>( &self, path: impl ReflectPath<'p> ) -> Result<&(dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read more§fn reflect_path_mut<'p>(
&mut self,
path: impl ReflectPath<'p>
) -> Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>
fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p> ) -> Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read more§fn path<'p, T>(
&self,
path: impl ReflectPath<'p>
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
fn path<'p, T>(
&self,
path: impl ReflectPath<'p>
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
path
. Read more§fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
path
. Read more§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.