diff --git a/crates/bevy_text/src/text2d.rs b/crates/bevy_text/src/text2d.rs index 13f9d1340590f..aac6c400feac2 100644 --- a/crates/bevy_text/src/text2d.rs +++ b/crates/bevy_text/src/text2d.rs @@ -103,7 +103,7 @@ pub fn extract_text2d_sprite( } let text_glyphs = &text_layout_info.glyphs; - let text_anchor = anchor.as_vec() * Vec2::new(1., -1.) - 0.5; + let text_anchor = -(anchor.as_vec() + 0.5); let alignment_offset = text_layout_info.size * text_anchor; let mut color = Color::WHITE; let mut current_section = usize::MAX; diff --git a/examples/2d/text2d.rs b/examples/2d/text2d.rs index e920ab5062557..100379e5aa3cc 100644 --- a/examples/2d/text2d.rs +++ b/examples/2d/text2d.rs @@ -7,6 +7,7 @@ use bevy::{ prelude::*, + sprite::Anchor, text::{BreakLineOn, Text2dBounds}, }; @@ -133,6 +134,29 @@ fn setup(mut commands: Commands, asset_server: Res) { ..default() }); }); + + for (text_anchor, color) in [ + (Anchor::TopLeft, Color::RED), + (Anchor::TopRight, Color::GREEN), + (Anchor::BottomRight, Color::BLUE), + (Anchor::BottomLeft, Color::YELLOW), + ] { + commands.spawn(Text2dBundle { + text: Text { + sections: vec![TextSection::new( + format!(" Anchor::{text_anchor:?} "), + TextStyle { + color, + ..slightly_smaller_text_style.clone() + }, + )], + ..Default::default() + }, + transform: Transform::from_translation(250. * Vec3::Y), + text_anchor, + ..default() + }); + } } fn animate_translation(