Update sprite_slice, spatial_audio_3d, spatial_audio_2d examples to use children macro (#18318)
# Objective Contributes to #18238 Updates the `sprite_slice`, `spatial_audio_3d` and `spatial_audio_2d` examples to use the `children!` macro. ## Solution Updates examples to use the Improved Spawning API merged in https://github.com/bevyengine/bevy/pull/17521 ## Testing - Did you test these changes? If so, how? - Opened the examples before and after and verified the same behavior was observed. I did this on Ubuntu 24.04.2 LTS using `--features wayland`. - Are there any parts that need more testing? - Other OS's and features can't hurt, but this is such a small change it shouldn't be a problem. - How can other people (reviewers) test your changes? Is there anything specific they need to know? - Run the examples yourself with and without these changes. - If relevant, what platforms did you test these changes on, and are there any important ones you can't test? - see above --- ## Showcase n/a ## Migration Guide n/a
This commit is contained in:
parent
01ea702fb5
commit
1e603558e6
@ -83,7 +83,7 @@ fn spawn_sprites(
|
|||||||
|
|
||||||
for (label, text_style, size, scale_mode) in cases {
|
for (label, text_style, size, scale_mode) in cases {
|
||||||
position.x += 0.5 * size.x;
|
position.x += 0.5 * size.x;
|
||||||
let mut cmd = commands.spawn((
|
commands.spawn((
|
||||||
Sprite {
|
Sprite {
|
||||||
image: texture_handle.clone(),
|
image: texture_handle.clone(),
|
||||||
custom_size: Some(size),
|
custom_size: Some(size),
|
||||||
@ -91,16 +91,14 @@ fn spawn_sprites(
|
|||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
Transform::from_translation(position),
|
Transform::from_translation(position),
|
||||||
));
|
children![(
|
||||||
cmd.with_children(|builder| {
|
|
||||||
builder.spawn((
|
|
||||||
Text2d::new(label),
|
Text2d::new(label),
|
||||||
text_style,
|
text_style,
|
||||||
TextLayout::new_with_justify(JustifyText::Center),
|
TextLayout::new_with_justify(JustifyText::Center),
|
||||||
Transform::from_xyz(0., -0.5 * size.y - 10., 0.0),
|
Transform::from_xyz(0., -0.5 * size.y - 10., 0.0),
|
||||||
bevy::sprite::Anchor::TopCenter,
|
bevy::sprite::Anchor::TopCenter,
|
||||||
));
|
)],
|
||||||
});
|
));
|
||||||
position.x += 0.5 * size.x + gap;
|
position.x += 0.5 * size.x + gap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,25 +43,23 @@ fn setup(
|
|||||||
));
|
));
|
||||||
|
|
||||||
let listener = SpatialListener::new(gap);
|
let listener = SpatialListener::new(gap);
|
||||||
commands
|
commands.spawn((
|
||||||
.spawn((
|
Transform::default(),
|
||||||
Transform::default(),
|
Visibility::default(),
|
||||||
Visibility::default(),
|
listener.clone(),
|
||||||
listener.clone(),
|
children![
|
||||||
))
|
|
||||||
.with_children(|parent| {
|
|
||||||
// left ear
|
// left ear
|
||||||
parent.spawn((
|
(
|
||||||
Sprite::from_color(RED, Vec2::splat(20.0)),
|
Sprite::from_color(RED, Vec2::splat(20.0)),
|
||||||
Transform::from_xyz(-gap / 2.0, 0.0, 0.0),
|
Transform::from_xyz(-gap / 2.0, 0.0, 0.0),
|
||||||
));
|
),
|
||||||
|
|
||||||
// right ear
|
// right ear
|
||||||
parent.spawn((
|
(
|
||||||
Sprite::from_color(LIME, Vec2::splat(20.0)),
|
Sprite::from_color(LIME, Vec2::splat(20.0)),
|
||||||
Transform::from_xyz(gap / 2.0, 0.0, 0.0),
|
Transform::from_xyz(gap / 2.0, 0.0, 0.0),
|
||||||
));
|
)
|
||||||
});
|
],
|
||||||
|
));
|
||||||
|
|
||||||
// example instructions
|
// example instructions
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
|
@ -35,27 +35,25 @@ fn setup(
|
|||||||
));
|
));
|
||||||
|
|
||||||
let listener = SpatialListener::new(gap);
|
let listener = SpatialListener::new(gap);
|
||||||
commands
|
commands.spawn((
|
||||||
.spawn((
|
Transform::default(),
|
||||||
Transform::default(),
|
Visibility::default(),
|
||||||
Visibility::default(),
|
listener.clone(),
|
||||||
listener.clone(),
|
children![
|
||||||
))
|
|
||||||
.with_children(|parent| {
|
|
||||||
// left ear indicator
|
// left ear indicator
|
||||||
parent.spawn((
|
(
|
||||||
Mesh3d(meshes.add(Cuboid::new(0.2, 0.2, 0.2))),
|
Mesh3d(meshes.add(Cuboid::new(0.2, 0.2, 0.2))),
|
||||||
MeshMaterial3d(materials.add(Color::from(RED))),
|
MeshMaterial3d(materials.add(Color::from(RED))),
|
||||||
Transform::from_translation(listener.left_ear_offset),
|
Transform::from_translation(listener.left_ear_offset),
|
||||||
));
|
),
|
||||||
|
|
||||||
// right ear indicator
|
// right ear indicator
|
||||||
parent.spawn((
|
(
|
||||||
Mesh3d(meshes.add(Cuboid::new(0.2, 0.2, 0.2))),
|
Mesh3d(meshes.add(Cuboid::new(0.2, 0.2, 0.2))),
|
||||||
MeshMaterial3d(materials.add(Color::from(LIME))),
|
MeshMaterial3d(materials.add(Color::from(LIME))),
|
||||||
Transform::from_translation(listener.right_ear_offset),
|
Transform::from_translation(listener.right_ear_offset),
|
||||||
));
|
)
|
||||||
});
|
],
|
||||||
|
));
|
||||||
|
|
||||||
// light
|
// light
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
|
Loading…
Reference in New Issue
Block a user