A convenient on-screen message print macro for bevy.

Overview

Bevy Debug Text Overlay

Bevy tracking Latest version Apache 2.0 Documentation

A proof of concept for adding a very convenient text overlay macro to the bevy game engine.

This is derived from the code I used during the first bevy game jam. There are major improvements: most notably the text doesn't jump around all the time, and each message can have its own color.

screen_print! is very convenient, if you are an incorrigible println-debugger, you will love this crate when working with bevy!

Usage

[dependencies]
bevy-debug-text-overlay = "2.0"

This bevy plugin is fairly trivial to use. You must:

  1. Add the OverlayPlugin to your app
  2. Add a UiCameraBundle entity
  3. Use the screen_print! macro wherever you want, just use it like you would use println!, no need to pass special arguments.

This will display on the top left of the screen the text for a short time.

Please see the screen_print! documentation for detailed usage instructions.

Code example

use bevy::prelude::*;
use bevy_debug_text_overlay::{screen_print, OverlayPlugin};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        // !!!!IMPORTANT!!!! Add the OverlayPlugin here
        .add_plugin(OverlayPlugin { font_size: 32.0, ..Default::default() })
        .add_startup_system(setup)
        .add_system(screen_print_text)
        .run();
}
fn setup(mut commands: Commands) {
    // !!!!IMPORTANT!!!! you must add a UiCameraBundle if you didn't already
    commands.spawn_bundle(UiCameraBundle::default());
}
// Notice how we didn't have to add any special system parameters
fn screen_print_text(time: Res<Time>) {
    let current_time = time.seconds_since_startup();
    let at_interval = |t: f64| current_time % t < time.delta_seconds_f64();
    let x = (13, 3.4, vec![1,2,3,4,5,6,7,8]);
    if at_interval(0.1) {
        let last_fps = 1.0 / time.delta_seconds();
        screen_print!(col: Color::CYAN, "fps: {last_fps:.0}");
        screen_print!("current time: {current_time:.2}")
    }
    if at_interval(2.0) {
        let col = Color::FUCHSIA;
        screen_print!(sec: 0.5, col: col, "every two seconds: {}, {:?}", x.0, x.2)
    }
    if at_interval(5.0) {
        screen_print!(sec: 3.0, "every five seconds: {x:#?}");
    }
}

This should look like as follow:

2022-03-16.08-23-27.mp4

Cargo features

builtin-font

The plugin provides its own ascii font by default, but if you want to disable it, you can disable the builtin-font cargo feature.

debug

It is possible to replace screen_print! by an empty macro by disabling the debug cargo feature. This also disables all of bevy-debug-text-overlay dependencies, since there is no code to run.

No further action is required to completely disable the plugin. Mock implementations are provided for release mod.

To use that feature, you can setup your Cargo.toml as follow:

# Add a debug feature to your own Cargo.toml, make it default
[features]
debug = ["bevy-debug-text-overlay/debug"]
default = ["debug"]

# Manually specify features for bevy-debug-text-overlay (omitting "debug")
bevy-debug-text-overlay = { version = "2.0", default-features = false, features = ["builtin-font"] }

Now when making your release build, you should use

cargo build --release --no-default-features

I'm aware that it can be cumbersome for some, please fill an issue if this really doesn't mix well with your own workflow.

Notes on performance

It seems that built without compiler optimization, displaying text on screen in bevy is a CPU hog, not sure why but it is (shrug). I designed the plugin with performance in mind, but the culprit is bevy not me.

You might be interested in enabling optimizations for dependencies in your debug builds.

Known limitations

I'm welcoming contributions if you have any fixes:

  • There is no way to specify the overlay position with regard to user-defined UI, so you might end up with the debug text showing behind your own UI.
  • There is a very custom, very dodgy resource allocation module. If someone can link me to a good 1D res alloc crate, I'd be happy to use it instead of block.
  • This is not part of bevy itself, so you gotta add it as a dependency to your app :(
  • You can't set it up so that it's displayed from the bottom up or to the right of the screen.

Changelog

  • 2.0.0: Breaking: bump bevy version to 0.7 (you should be able to upgrade from 1.0.0 without changing your code)

Version matrix

bevy latest supporting version
0.7 2.0.0
0.6 1.0.0

API stability warning

This is a tinny crate so it's literally impossible to cause major breaking changes. But I'm not convinced the current macro API is optimal, and it might change in the future.

License

This library is licensed under Apache 2.0.

Font

The font in screen_debug_text.ttf is derived from Adobe SourceSans, licensed under the SIL OFL. see file at licenses/SIL Open Font License.txt.

You might also like...
A Bevy plugin for loading the LDtk 2D tile map format.
A Bevy plugin for loading the LDtk 2D tile map format.

bevy_ldtk ( Tileset from "Cavernas" by Adam Saltsman ) A Bevy plugin for loading LDtk tile maps. Usage use bevy::prelude::*; use bevy_ldtk::*; fn mai

Basic first-person fly camera for the Bevy game engine

bevy_flycam A basic first-person fly camera for Bevy 0.4 Controls WASD to move horizontally SPACE to ascend LSHIFT to descend ESC to grab/release curs

An ergonomic physics API for bevy games.

Heron An ergonomic physics API for 2d and 3d bevy games. (powered by rapier) How it looks like fn main() { App::build() .add_plugins(DefaultPlug

Inspector plugin for the bevy game engine
Inspector plugin for the bevy game engine

bevy-inspector-egui This crate provides the ability to annotate structs with a #[derive(Inspectable)], which opens a debug interface using egui where

A plugin for Egui integration into Bevy
A plugin for Egui integration into Bevy

bevy_egui This crate provides a Egui integration for the Bevy game engine. Features: Desktop and web (bevy_webgl2) platforms support Clipboard (web su

Crossterm plugin for the bevy game engine
Crossterm plugin for the bevy game engine

What is bevy_crossterm? bevy_crossterm is a Bevy plugin that uses crossterm as a renderer. It provides custom components and events which allow users

A 4X style camera for bevy.

A 4X style camera for bevy. Demo Default Key Bindings: W / A / S / D / Arrow Keys / Mouse Left - Move along the horizontal plane Q / E / Mouse Right -

Game physics in one weekend with bevy

Game Physics in a Weekend (in Rust) This project is an implementation of the Game Physics in a Weekend book using the Rust programming language and th

A Bevy plugin to use Kira for game audio

Bevy Kira audio This bevy plugin is intended to try integrating Kira into Bevy. The end goal would be to replace or update bevy_audio, if Kira turns o

Comments
  • Add example/simplify usage of multi target viewports to render on top of other UI elements

    Add example/simplify usage of multi target viewports to render on top of other UI elements

    Since camera-driven rendering, it should be possible to render the log UI to a different target than the default one and assign it a priority higher than it, allowing to draw over everything esle.

    Alternatives (choice still open)

    • Add an example demonstrating how to do this in user code
    • Add a config toggle that let the library do it for the user
    • See where https://github.com/bevyengine/bevy/pull/5892 goes, this should 100% be the favored solution.
    enhancement 
    opened by nicopap 0
  • when using screen-print in query.iterator may loss message

    when using screen-print in query.iterator may loss message

    hello , i feel confused when i am using the screen_paint! in my query in the system function, my query type is such as query: Query<&GlobalTrasnform>, then the using postion is screen_print!("{:?}", trans.translation())

    bug 
    opened by kyrosle 2
Owner
Nicola Papale
Rustacean and game developer
Nicola Papale
Highly customizable splash screen library for Bevy games.

bevy_intro_screen This is a versatile Bevy library designed to create engaging and customizable introductory screens for your game. Initially conceive

Aarav Shah 4 Aug 13, 2024
Simple rust asset handling derive macro for enums, and a proc-macro learning resource!

asset-derive Summary • Todos • Docs Summary Simple Rust asset loading derive macro for Enums, and a resource for learning proc-macros! Please feel fre

Shadorain 5 Feb 9, 2023
A tool to display the minimap of a game larger on a second screen

maximap A tool to display the minimap of a game larger on a second screen. Should work on all operating systems supported by captrs and rust_minifb, s

Richard Baumann 18 Oct 11, 2022
A proof of concept Linux screen reader, with minimal features.

Odilia A proof of concept Linux screen reader, with minimal features. Status: prototype We're breaking things daily. This is not usable whatsoever, an

Odilia 43 Aug 15, 2022
Minecraft-esque voxel engine prototype made with the bevy game engine. Pending bevy 0.6 release to undergo a full rewrite.

vx_bevy A voxel engine prototype made using the Bevy game engine. Goals and features Very basic worldgen Animated chunk loading (ala cube world) Optim

Lucas Arriesse 125 Dec 31, 2022
bevy-hikari is an implementation of voxel cone tracing global illumination with anisotropic mip-mapping in Bevy

Bevy Voxel Cone Tracing bevy-hikari is an implementation of voxel cone tracing global illumination with anisotropic mip-mapping in Bevy. Bevy Version

研究社交 208 Dec 27, 2022
A simple extension for `bevy-editor-pls` to support tilemap editing right inside the bevy app.

What is this This is a simple tilemap editor plugin, that hooks right into bevy_editor_pls to work with bevy_ecs_tilemap. It works completely within i

null 3 May 8, 2023
Bevy Simple Portals is a Bevy game engine plugin aimed to create portals.

Portals for Bevy Bevy Simple Portals is a Bevy game engine plugin aimed to create portals. Those portals are (for now) purely visual and can be used t

Sélène Amanita 11 May 28, 2023
Minecraft using Bevy and Bevy-Meshem

minecraft_bevy Minecraft_bevy was built to showcase bevy_meshem. After a week of developing it has: Chunk loading / unloading each chunk's mesh is bei

Adam 7 Oct 4, 2023
This library implements the flip-flop operator from Perl and Ruby as a Rust macro.

flip_flop.rs This library implements the flip-flop operator from Perl and Ruby as a Rust macro. Changelog April 1, 2024: Version 1.0.0. Usage The flip

Utkarsh Kukreti 7 Apr 4, 2024