Hello everyone I am trying write the score in the top left corner of the window but for some reason it is not working. Here is the code I used to spawn the text:
commands
.spawn(TextBundle{
text: Text{value: "Score:".to_string(),
font: assets.load("FiraSans-Bold.ttf"),
style:TextStyle{
font_size:30.0,
color:Color::WHITE,
..Default::default()},..Default::default()},
transform: Transform::from_translation(Vec3::new(-380.0,-380.0,2.0)),
..Default::default()
})
.with(TextTag);
Window is 800 by 800. Any help is appreciated.
You may need to add the CameraUiBundle if you did not yet do it.
commands
.spawn(CameraUiBundle::default())
.spawn(TextBundle{
...
})
.with(TextTag);
You might want to do that in your initial setup system in which you also add the camera.
The Bevy version used when answering was 0.4.
Another reason (in bevy 0.8) might be that there's no default font in bevy (check out this answer)
What you'd need to do would be to download a .ttf file, and then load it when spawning the text.
TextStyle {
font_size: 50.0,
color: Color::WHITE,
font: asset_server.load("your_font.ttf"),
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With