Skip to content

Commit dac0b10

Browse files
authored
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 #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
1 parent acd4451 commit dac0b10

File tree

3 files changed

+26
-32
lines changed

3 files changed

+26
-32
lines changed

examples/2d/sprite_slice.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,24 +83,22 @@ fn spawn_sprites(
8383

8484
for (label, text_style, size, scale_mode) in cases {
8585
position.x += 0.5 * size.x;
86-
let mut cmd = commands.spawn((
86+
commands.spawn((
8787
Sprite {
8888
image: texture_handle.clone(),
8989
custom_size: Some(size),
9090
image_mode: scale_mode,
9191
..default()
9292
},
9393
Transform::from_translation(position),
94-
));
95-
cmd.with_children(|builder| {
96-
builder.spawn((
94+
children![(
9795
Text2d::new(label),
9896
text_style,
9997
TextLayout::new_with_justify(JustifyText::Center),
10098
Transform::from_xyz(0., -0.5 * size.y - 10., 0.0),
10199
bevy::sprite::Anchor::TopCenter,
102-
));
103-
});
100+
)],
101+
));
104102
position.x += 0.5 * size.x + gap;
105103
}
106104
}

examples/audio/spatial_audio_2d.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,23 @@ fn setup(
4343
));
4444

4545
let listener = SpatialListener::new(gap);
46-
commands
47-
.spawn((
48-
Transform::default(),
49-
Visibility::default(),
50-
listener.clone(),
51-
))
52-
.with_children(|parent| {
46+
commands.spawn((
47+
Transform::default(),
48+
Visibility::default(),
49+
listener.clone(),
50+
children![
5351
// left ear
54-
parent.spawn((
52+
(
5553
Sprite::from_color(RED, Vec2::splat(20.0)),
5654
Transform::from_xyz(-gap / 2.0, 0.0, 0.0),
57-
));
58-
55+
),
5956
// right ear
60-
parent.spawn((
57+
(
6158
Sprite::from_color(LIME, Vec2::splat(20.0)),
6259
Transform::from_xyz(gap / 2.0, 0.0, 0.0),
63-
));
64-
});
60+
)
61+
],
62+
));
6563

6664
// example instructions
6765
commands.spawn((

examples/audio/spatial_audio_3d.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,25 @@ fn setup(
3535
));
3636

3737
let listener = SpatialListener::new(gap);
38-
commands
39-
.spawn((
40-
Transform::default(),
41-
Visibility::default(),
42-
listener.clone(),
43-
))
44-
.with_children(|parent| {
38+
commands.spawn((
39+
Transform::default(),
40+
Visibility::default(),
41+
listener.clone(),
42+
children![
4543
// left ear indicator
46-
parent.spawn((
44+
(
4745
Mesh3d(meshes.add(Cuboid::new(0.2, 0.2, 0.2))),
4846
MeshMaterial3d(materials.add(Color::from(RED))),
4947
Transform::from_translation(listener.left_ear_offset),
50-
));
51-
48+
),
5249
// right ear indicator
53-
parent.spawn((
50+
(
5451
Mesh3d(meshes.add(Cuboid::new(0.2, 0.2, 0.2))),
5552
MeshMaterial3d(materials.add(Color::from(LIME))),
5653
Transform::from_translation(listener.right_ear_offset),
57-
));
58-
});
54+
)
55+
],
56+
));
5957

6058
// light
6159
commands.spawn((

0 commit comments

Comments
 (0)