bevy_bitmap_text 0.2.0

Glyph-as-Entity dynamic atlas text rendering for Bevy
Documentation

bevy_bitmap_text

license

bevy_bitmap_text — Glyph-as-Entity dynamic atlas text rendering for Bevy.

English Simplified Chinese
English 简体中文

Introduction

Standard text rendering in game engines is usually a monolith: an entire sentence gets baked into a single mesh. But what if you want just one specific letter to shake violently, bounce up and down, or dynamically shift its color? Especially for pixel games, trying to achieve that classic, expressive "retro" feel within high-level modern text systems can be surprisingly frustrating.

So I thought: why not simplify everything and go back to the bitmap approach? That's how bevy_bitmap_text came to be. It is a text rendering backend for Bevy that spawns each character as its own independent ECS entity with a Sprite component.

By treating glyphs as individual bitmap sprites, it hands the power back to Bevy's standard ECS. You want a word to wave like a flag? Just attach a WaveEffect component to those character entities. The plugin automatically handles the heavy lifting: on-the-fly font rasterization, atlas packing, layout, and keeping all those entities synchronized.

— that's it, a simple text alternative. Take it if you want.

Features

  • 🧩 Glyph-as-Entity architecture — each character is a separate Sprite entity, enabling per-character animation and styling via standard ECS
  • 🔠 Dynamic glyph atlas — on-demand rasterization with fontdue and rectangle packing via etagere
  • ⌨️ Typewriter effect — built-in GlyphReveal component for progressive character reveal
  • Per-character effectsShakeEffect and WaveEffect components for jitter and sine-wave animations
  • 🎨 Color tags — inline {#RRGGBB:text} markup for per-segment coloring
  • 🖌️ Text styling — configurable font, size, color, alignment, anchor, line height, character spacing, and word spacing
  • ↩️ Auto line-wrapping — optional max_width for automatic word wrap

How to Use

  1. Add the dependency to your Cargo.toml:

    [dependencies]
    bevy_bitmap_text = { path = "crates/bevy_bitmap_text" }
    
  2. Register the plugin:

    use bevy::prelude::*;
    use bevy_bitmap_text::{BitmapTextPlugin, FontDirectories};
    
    fn main() {
        App::new()
            .add_plugins(DefaultPlugins)
            .insert_resource(FontDirectories {
                directories: vec!["assets/fonts".to_string()],
            })
            .add_plugins(BitmapTextPlugin::default())
            .add_systems(Startup, setup)
            .run();
    }
    
  3. Spawn a text block:

    use bevy_bitmap_text::*;
    
    fn setup(mut commands: Commands) {
        commands.spawn(Camera2d);
        commands.spawn((
            TextBlock::new("Hello, world!"),
            TextBlockStyling {
                font: FontId::from_name("my_font"),
                size_px: 32,
                world_scale: 32.0,
                ..default()
            },
        ));
    }
    
  4. Typewriter effect:

    commands.spawn((
        TextBlock::new("Revealing text..."),
        TextBlockStyling { /* ... */ },
        GlyphReveal { visible_count: 0 },
    ));
    // Increment `visible_count` each frame to reveal characters one by one.
    
  5. Color tags:

    use bevy_bitmap_text::parse_text_to_segments;
    let segments = parse_text_to_segments("{#FF0000:Red} and {#00FF00:Green}");
    commands.spawn((
        TextBlock::from_segments(segments),
        TextBlockStyling { /* ... */ },
    ));
    

How to Build

Prerequisites

  • Rust 1.85 or later (edition 2024)
  • Bevy 0.18

Build Steps

  1. Build the crate:

    cargo build -p bevy_bitmap_text
    
  2. Run tests:

    cargo test -p bevy_bitmap_text
    
  3. Run the demo:

    cargo run -p bevy_bitmap_text --example demo
    

Dependencies

This project uses the following crates:

Crate Version Description
bevy 0.18 Game engine framework (asset, color, render, sprite)
fontdue 0.7 Lightweight font rasterization
etagere 0.2 Rectangle atlas packing
log 0.4 Logging facade

Contributing

Contributions are welcome! Whether you want to fix a bug, add a feature, or improve documentation:

  • Submit an Issue or Pull Request.
  • Share ideas and discuss design or architecture.

License

This project is licensed under either of

at your option.