Path: blob/main/examples/gizmos/anchored_text_gizmos.rs
9458 views
//! Example demonstrating how to use text gizmos with anchors.1//!2//! The anchor selects which part of the text is aligned to the isometry’s position:3//! `(0, 0)` center, `(-0.5, 0.0)` left edge, `(0.0, 0.5)` top edge.45use bevy::color::palettes::css::{BLUE, GREEN, ORANGE, RED, YELLOW};6use bevy::prelude::*;78fn main() {9App::new()10.add_plugins(DefaultPlugins)11.add_systems(Startup, setup_camera)12.add_systems(Update, anchors)13.run();14}1516fn setup_camera(mut commands: Commands) {17commands.spawn(Camera2d);18}1920fn anchors(mut text_gizmos: Gizmos, time: Res<Time>) {21let t = time.elapsed_secs();22for (label, anchor, color) in [23("left", vec2(-0.5, 0.0), RED),24("right", vec2(0.5, 0.0), ORANGE),25("center", Vec2::ZERO, YELLOW),26("top", vec2(0.0, 0.5), GREEN),27("bottom", vec2(0.0, -0.5), BLUE),28] {29let position = Vec2::splat(350.0) * anchor;30text_gizmos.text_2d(31Isometry2d::from_translation(position),32"+",3312.,34Vec2::ZERO,35Color::WHITE,36);37text_gizmos.text_2d(38Isometry2d::new(position, Rot2::radians(t)),39label,4025.,41anchor,42color,43);44}45}464748