Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bevy text isn't displayed and I don't know why

Tags:

rust

bevy

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.

like image 908
Nakroxis Avatar asked Nov 04 '25 05:11

Nakroxis


2 Answers

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.

like image 161
MKroehnert Avatar answered Nov 05 '25 19:11

MKroehnert


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"),
},
like image 29
aurelia Avatar answered Nov 05 '25 19:11

aurelia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!