macro_rules! screen_print {
    (push, col: $color:expr, $text:expr $(, $fmt_args:expr)*) => { ... };
    (col: $color:expr, $text:expr $(, $fmt_args:expr)*) => { ... };
    (push, sec: $timeout:expr, col: $color:expr, $text:expr $(, $fmt_args:expr)*) => { ... };
    (sec: $timeout:expr, col: $color:expr, $text:expr $(, $fmt_args:expr)*) => { ... };
    (push, sec: $timeout:expr, $text:expr $(, $fmt_args:expr)*) => { ... };
    (sec: $timeout:expr, $text:expr $(, $fmt_args:expr)*) => { ... };
    (push, $text:expr $(, $fmt_args:expr)*) => { ... };
    ($text:expr $(, $fmt_args:expr)*) => { ... };
    (@impl sec: $timeout:expr, col: $color:expr, $text:expr $(, $fmt_args:expr)*) => { ... };
    (@impl push, sec: $timeout:expr, col: $color:expr, $text:expr $(, $fmt_args:expr)*) => { ... };
}
Expand description

Display text on top left corner of the screen.

The same screen_print! invocation can only have a single text displayed on screen at the same time, unless specified otherwise.

§Limitations

  • Entity count: Entities used for displaying text are never despawned, so if at one point you have very many messages displayed at the same time, it might slow down afterward your game. Note that aready spawned entities are reused, so you need not fear leaks.
  • Max call per frame: at most 4096 messages can be printed per frame, exceeding that amount will panic.

§Usage

Call screen_print! like you would call any format!-style macros from the standard lib.

You can also customize color and timeout, by adding prefix optional arguments (only supported in this order):

  1. push: Do not overwrite previous text value. This allows printing multiple messages from the same macro call, you can use this in loops, or for messages that makes sense to duplicate on screen. Be advised! Using a push message once per frame will spam the log.
  2. sec: <timeout>: specify in seconds for how long the text shows up (default is 7 seconds)
  3. col: <color>: specify the color of the text. Default is fallback_color provided in OverlayPlugin, which itself defaults to yellow.
use bevy_debug_text_overlay::{screen_print, OverlayPlugin};
use bevy::prelude::Color;

let x = (13, 3.4, vec![1,2,3,4,5,6,7,8]);
screen_print!("multiline: {x:#?}");
screen_print!(push, "This shows multiple times");
screen_print!(sec: 6.0, "first and second fields: {}, {}", x.0, x.1);
screen_print!(col: Color::BLUE, "single line: {x:?}");
screen_print!(sec: 10.0, col: Color::BLUE, "last field: {:?}", x.2);