forked from blaind/bevy_text_mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2d_text.rs
41 lines (36 loc) · 1.14 KB
/
2d_text.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use bevy::prelude::*;
use bevy_text_mesh::TextMeshPlugin;
fn main() {
App::new()
.add_plugins((DefaultPlugins, TextMeshPlugin)) // TextMeshPlugin for interop check
.add_systems(Startup, setup)
.add_systems(Update, animate_rotation)
.run();
}
#[derive(Component)]
struct AnimateRotation;
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let font = asset_server.load("fonts/FiraMono-Medium.ttf");
let text_style = TextStyle {
font,
font_size: 60.0,
color: Color::WHITE,
};
let text_alignment = TextAlignment::Center;
commands.spawn(Camera2dBundle::default());
commands
.spawn(Text2dBundle {
text: Text::from_section("standard 2d text works too", text_style.clone())
.with_alignment(text_alignment),
..default()
})
.insert(AnimateRotation);
}
fn animate_rotation(
time: Res<Time>,
mut query: Query<&mut Transform, (With<Text>, With<AnimateRotation>)>,
) {
for mut transform in &mut query {
transform.rotation = Quat::from_rotation_z(time.elapsed_seconds_f64().cos() as f32);
}
}