-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
convert more examples to new spawn api #20876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
d643d89
b8cf0bf
755b967
2c5aea0
a542e90
729272b
61287f1
bf0fa92
091d68c
27e53a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,35 +151,29 @@ fn setup( | |
| player, | ||
| )) | ||
| .id(); | ||
| commands | ||
| .entity(planet_entity) | ||
| .insert(AnimationTarget { | ||
| 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(( | ||
| Transform::default(), | ||
| Visibility::default(), | ||
| orbit_controller, | ||
| }, | ||
| Children::spawn_one(( | ||
| Transform::default(), | ||
| Visibility::default(), | ||
| orbit_controller, | ||
| AnimationTarget { | ||
| id: orbit_controller_animation_target_id, | ||
| player: planet_entity, | ||
| }, | ||
| Children::spawn_one(( | ||
| Mesh3d(meshes.add(Cuboid::new(0.5, 0.5, 0.5))), | ||
| MeshMaterial3d(materials.add(Color::srgb(0.3, 0.9, 0.3))), | ||
| Transform::from_xyz(1.5, 0.0, 0.0), | ||
| AnimationTarget { | ||
| id: orbit_controller_animation_target_id, | ||
| id: satellite_animation_target_id, | ||
| player: planet_entity, | ||
| }, | ||
| )) | ||
| .with_children(|p| { | ||
| // The satellite, placed at a distance of the planet | ||
| p.spawn(( | ||
| Mesh3d(meshes.add(Cuboid::new(0.5, 0.5, 0.5))), | ||
| MeshMaterial3d(materials.add(Color::srgb(0.3, 0.9, 0.3))), | ||
| Transform::from_xyz(1.5, 0.0, 0.0), | ||
| AnimationTarget { | ||
| id: satellite_animation_target_id, | ||
| player: planet_entity, | ||
| }, | ||
| satellite, | ||
| )); | ||
| }); | ||
| }); | ||
| satellite, | ||
| )), | ||
| )), | ||
| )); | ||
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,43 +123,38 @@ fn setup( | |
| // Build the UI. We have a parent node that covers the whole screen and | ||
| // contains the `AnimationPlayer`, as well as a child node that contains the | ||
| // text to be animated. | ||
| commands | ||
| .spawn(( | ||
| // Cover the whole screen, and center contents. | ||
| Node { | ||
| position_type: PositionType::Absolute, | ||
| top: px(0), | ||
| left: px(0), | ||
| right: px(0), | ||
| bottom: px(0), | ||
| justify_content: JustifyContent::Center, | ||
| align_items: AlignItems::Center, | ||
| ..default() | ||
| }, | ||
| animation_player, | ||
| AnimationGraphHandle(animation_graph), | ||
| )) | ||
| .with_children(|builder| { | ||
| // Build the text node. | ||
| let player = builder.target_entity(); | ||
| builder | ||
| .spawn(( | ||
| Text::new("Bevy"), | ||
| TextFont { | ||
| font: asset_server.load("fonts/FiraSans-Bold.ttf"), | ||
| font_size: 24.0, | ||
| ..default() | ||
| }, | ||
| TextColor(Color::Srgba(Srgba::RED)), | ||
| TextLayout::new_with_justify(Justify::Center), | ||
| )) | ||
| // Mark as an animation target. | ||
| .insert(AnimationTarget { | ||
| id: animation_target_id, | ||
| player, | ||
| }) | ||
| .insert(animation_target_name); | ||
| }); | ||
| let mut entity = commands.spawn(( | ||
| // Cover the whole screen, and center contents. | ||
| Node { | ||
| position_type: PositionType::Absolute, | ||
| top: px(0), | ||
| left: px(0), | ||
| right: px(0), | ||
| bottom: px(0), | ||
| justify_content: JustifyContent::Center, | ||
| align_items: AlignItems::Center, | ||
| ..default() | ||
| }, | ||
| animation_player, | ||
| AnimationGraphHandle(animation_graph), | ||
| )); | ||
|
|
||
| let player = entity.id(); | ||
| entity.insert(Children::spawn_one(( | ||
| Text::new("Bevy"), | ||
| TextFont { | ||
| font: asset_server.load("fonts/FiraSans-Bold.ttf"), | ||
| font_size: 24.0, | ||
| ..default() | ||
| }, | ||
| TextColor(Color::Srgba(Srgba::RED)), | ||
| TextLayout::new_with_justify(Justify::Center), | ||
| AnimationTarget { | ||
| id: animation_target_id, | ||
| player, | ||
| }, | ||
| animation_target_name, | ||
| ))); | ||
|
||
| } | ||
|
|
||
| // A type that represents the color of the first text section. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a fan of this one, but won't block on it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I am either but I also didn't know about this functionality so maybe it's worth it!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the
ecs/hierarchy.rsexample would lend itself quite well to demonstrating the different possible methods for inserting children/handling relations. Would you be more against having this in this example if that example included a demonstration ofSpawnIter?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API in this case just looks clunky to me, no matter if it's also used in other places. But that might just be me being more used to the "old" way :)