一键导入
bevy-text
Reference for text rendering in Bevy — Text vs Text2d, styling, text spans, changing text at runtime, clicking text, and font rendering.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Reference for text rendering in Bevy — Text vs Text2d, styling, text spans, changing text at runtime, clicking text, and font rendering.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Reference for Avian physics engine — rigid bodies, colliders, joints, spatial queries, collision events, character controllers, and debug rendering.
Reference for loading, managing, and tracking assets in Bevy — AssetServer, handles, loading states, events, custom loaders, and hot reloading.
Reference for playing and controlling audio in Bevy — AudioPlayer, AudioSink, spatial audio, volume, and playback settings.
Reference for Bevy Scene Notation (BSN) — the bsn! macro for defining inline scenes with components, children, relationships, observers, and dynamic props.
Reference for cameras in Bevy — Camera2d, Camera3d, viewports, projection, render layers, mouse-to-world, and free camera controllers.
Reference for Bevy Commands — spawning/despawning entities, inserting/removing components, custom commands, trait extensions, and testing.
| name | bevy-text |
| description | Reference for text rendering in Bevy — Text vs Text2d, styling, text spans, changing text at runtime, clicking text, and font rendering. |
| metadata | {"crate":"bevy_text","bevy":"0.19"} |
| Component | Use case |
|---|---|
Text | UI text (fixed position, in HUD/inventory) |
Text2d | Scene text (floating damage, world-space labels) |
// In scene
commands.spawn((
Text2d::new("Hello"),
TextColor(Color::WHITE),
TextFont::from(font_handle).with_font_size(60.),
TextLayout::new_with_justify(Justify::Center),
));
// In UI
commands.spawn((
Node { position_type: PositionType::Absolute, bottom: px(5.0), right: px(5.0), ..default() },
Text::new("Hello"),
TextFont::from(font_handle),
));
TextLayout — alignment, line break behaviorTextFont — font, font sizeTextColor — color overridecommands.spawn((
Text::new("Here is some text. But "),
TextFont::from(regular_font),
children![(
TextSpan::new("this part is bold"),
TextFont::from(bold_font),
)],
));
fn update(mut texts: Query<&mut Text, With<ItemName>>) {
for mut text in &mut texts {
text.0 = "New text".to_string();
}
}
fn handle_click(event: On<Pointer<Click>>, mut query: Query<&mut Text2d>) {
query.get_mut(event.entity).unwrap().0 = "Clicked!".to_string();
}
commands.spawn(Text2d::new("Click me")).observe(handle_click);
Supported: ttf, otf. Default font: Fira Mono. Load via AssetServer.
Bevy 0.19+ supports OpenType font features.