mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
fix ui in font atlas and breakout examples
This commit is contained in:
parent
db665b96c0
commit
a2c1a90695
3 changed files with 21 additions and 11 deletions
|
@ -39,7 +39,7 @@ fn update_node_entity(
|
|||
parent_result: Option<f32>,
|
||||
previous_result: Option<f32>,
|
||||
) -> Option<f32> {
|
||||
let mut transform = node_query.get_mut::<LocalTransform>(entity).unwrap();
|
||||
let mut transform = node_query.get_mut::<LocalTransform>(entity).ok()?;
|
||||
let mut z = UI_Z_STEP;
|
||||
let parent_global_z = parent_result.unwrap();
|
||||
if let Some(previous_global_z) = previous_result {
|
||||
|
|
|
@ -40,8 +40,9 @@ fn setup(
|
|||
) {
|
||||
// Add the game's entities to our world
|
||||
commands
|
||||
// camera
|
||||
// cameras
|
||||
.spawn(Camera2dComponents::default())
|
||||
.spawn(UiCameraComponents::default())
|
||||
// paddle
|
||||
.spawn(SpriteComponents {
|
||||
material: materials.add(Color::rgb(0.2, 0.2, 0.8).into()),
|
||||
|
@ -75,6 +76,12 @@ fn setup(
|
|||
},
|
||||
},
|
||||
style: Style {
|
||||
position_type: PositionType::Absolute,
|
||||
position: Rect {
|
||||
top: Val::Px(5.0),
|
||||
left: Val::Px(5.0),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
|
|
|
@ -41,9 +41,17 @@ fn atlas_render_system(
|
|||
for (_size, font_atlas) in set.iter() {
|
||||
state.added = true;
|
||||
let texture_atlas = texture_atlases.get(&font_atlas.texture_atlas).unwrap();
|
||||
commands.spawn(SpriteComponents {
|
||||
commands.spawn(ImageComponents {
|
||||
material: materials.add(texture_atlas.texture.into()),
|
||||
translation: Vec3::new(-300.0, 0., 0.0).into(),
|
||||
style: Style {
|
||||
position_type: PositionType::Absolute,
|
||||
position: Rect {
|
||||
top: Val::Px(0.0),
|
||||
left: Val::Px(0.0),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
});
|
||||
break;
|
||||
|
@ -65,15 +73,10 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut state: ResM
|
|||
let font_handle = asset_server.load("assets/fonts/FiraSans-Bold.ttf").unwrap();
|
||||
state.handle = font_handle;
|
||||
commands
|
||||
// 2d camera
|
||||
.spawn(Camera2dComponents::default())
|
||||
// texture
|
||||
.spawn(UiCameraComponents::default())
|
||||
.spawn(TextComponents {
|
||||
style: Style {
|
||||
size: Size {
|
||||
width: Val::Px(250.0),
|
||||
height: Val::Px(60.0),
|
||||
},
|
||||
size: Size::new(Val::Px(250.0), Val::Px(60.0)),
|
||||
..Default::default()
|
||||
},
|
||||
text: Text {
|
||||
|
|
Loading…
Reference in a new issue