fix ui in font atlas and breakout examples

This commit is contained in:
Carter Anderson 2020-07-29 01:16:42 -07:00
parent db665b96c0
commit a2c1a90695
3 changed files with 21 additions and 11 deletions

View file

@ -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 {

View file

@ -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()

View file

@ -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 {