Skip to content

Latest commit

 

History

History
54 lines (41 loc) · 1.43 KB

displaying_texts.md

File metadata and controls

54 lines (41 loc) · 1.43 KB

Displaying Texts

To have texts on the screen, we can use Text2dBundle.

fn setup(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());

    commands.spawn(Text2dBundle {
        text: Text::from_section("Hello", TextStyle::default()),
        ..default()
    });
}

We set the Text of Text2dBundle and initialize it to a string that is going to be displayed. Currently, we use TextStyle::default() for the default style.

The full code is as follows:

use bevy::{
    app::{App, Startup},
    core_pipeline::core_2d::Camera2dBundle,
    ecs::system::Commands,
    text::{Text, Text2dBundle, TextStyle},
    utils::default,
    DefaultPlugins,
};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());

    commands.spawn(Text2dBundle {
        text: Text::from_section("Hello", TextStyle::default()),
        ..default()
    });
}

Result:

Displaying Texts

➡️ Next: Font Styles

📘 Back: Table of contents