Crates.io | bevy_image_font |
lib.rs | bevy_image_font |
version | |
source | src |
created_at | 2024-12-30 21:03:23.647858 |
updated_at | 2025-01-01 16:04:36.095238 |
description | Render pixel fonts from PNGs in Bevy. |
homepage | |
repository | https://github.com/ilyvion/bevy_image_font |
max_upload_size | |
id | 1499440 |
Cargo.toml error: | TOML parse error at line 21, column 1 | 21 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
bevy_image_font
bevy_image_font
enables rendering fonts stored as single images (e.g., PNG), with each letter at a predefined position. This crate focuses specifically on image-based fonts, often called "pixel fonts," used in game development. The term "image font" was chosen for precision, as bitmap fonts in formats like OTB might also be referred to as "pixel fonts."
Add the following to your Cargo.toml
:
[dependencies]
bevy = "0.15"
bevy_image_font = "0.7"
Add an ImageFontText
component to an entity along with:
Sprite
and a ImageFontPreRenderedText
components to render the text onto the associated Sprite
, orImageNode
and ImageFontPreRenderedUiText
components to render the text onto the associated ImageNode
, orImageFontSpriteText
component for atlas-based text rendering.Here's a minimal example of using bevy_image_font
to render text.1 :
use bevy::prelude::*;
use bevy_image_font::{ImageFontPlugin, ImageFontText};
#[cfg(feature = "atlas_sprites")]
use bevy_image_font::atlas_sprites::ImageFontSpriteText;
fn main() {
App::new()
.add_plugins((DefaultPlugins, ImageFontPlugin))
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let font_handle = asset_server.load("path/to/font_layout.image_font.ron");
commands.spawn((
#[cfg(feature = "atlas_sprites")]
ImageFontSpriteText::default(),
ImageFontText::default()
.text("Hello, world!")
.font(font_handle.clone()),
));
}
This example sets up a simple Bevy application with an ImageFontText
component, rendering "Hello, world!" using a specified font image and layout.
See examples for more details:
bevy_asset_loader
for texture and font handling.Bevy anchors sprites at the center by default, which may cause odd-dimensioned sprites to appear blurry. To avoid this, use non-Center
anchors like Anchor::TopLeft
or adjust sprite translations. Refer to the rendered sprite example for details.
atlas_sprites
feature if you don't use ImageFontSpriteText
.rendered
feature if you don't use ImageFontPreRenderedText
or ImageFontPreRenderedUiText
. This removes the dependency on the image
crate.ui
feature if you don't use ImageFontPreRenderedUiText
to remove a dependency on the bevy/bevy_ui
feature.image
and enable the relevant features.Bevy Version | Crate Version |
---|---|
0.15 | 0.6, 0.7 |
0.14 | 0.5 |
For detailed changes across versions, see the Changelog. Each GitHub Release which is created each time the crate is published also includes the relevant section of the changelog in its release notes for easy reference.
git config --local core.hooksPath .githooks
cargo install cargo-hack --locked
PRs to support the latest Bevy releases are welcome!
Sample font by gnsh.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Ignore the #[cfg(feature = "...")]
lines in the example; they're only there to satisfy the compiler when running it as a doc test for this README. ↩