-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Expand file tree
/
Copy pathanchored_text_gizmos.rs
More file actions
46 lines (42 loc) · 1.27 KB
/
anchored_text_gizmos.rs
File metadata and controls
46 lines (42 loc) · 1.27 KB
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
42
43
44
45
46
//! Example demonstrating how to use text gizmos with anchors.
//!
//! The anchor selects which part of the text is aligned to the isometry’s position:
//! `(0, 0)` center, `(-0.5, 0.0)` left edge, `(0.0, 0.5)` top edge.
use bevy::color::palettes::css::{BLUE, GREEN, ORANGE, RED, YELLOW};
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup_camera)
.add_systems(Update, anchors)
.run();
}
fn setup_camera(mut commands: Commands) {
commands.spawn(Camera2d);
}
fn anchors(mut text_gizmos: Gizmos, time: Res<Time>) {
let t = time.elapsed_secs();
for (label, anchor, color) in [
("left", vec2(-0.5, 0.0), RED),
("right", vec2(0.5, 0.0), ORANGE),
("center", Vec2::ZERO, YELLOW),
("top", vec2(0.0, 0.5), GREEN),
("bottom", vec2(0.0, -0.5), BLUE),
] {
let position = Vec2::splat(350.0) * anchor;
text_gizmos.text_2d(
Isometry2d::from_translation(position),
"+",
12.,
Vec2::ZERO,
Color::WHITE,
);
text_gizmos.text_2d(
Isometry2d::new(position, Rot2::radians(t)),
label,
25.,
anchor,
color,
);
}
}