bevy_simple_screen_boxing

Crates.iobevy_simple_screen_boxing
lib.rsbevy_simple_screen_boxing
version0.2.0-rc.2
created_at2025-06-14 18:41:39.326394+00
updated_at2025-09-13 16:55:31.236157+00
descriptionA simple, but small, crate that aims to make Letter/Pillar Boxing in Bevy easy.
homepage
repositoryhttps://github.com/Sapein/bevy_simple_screen_boxing
max_upload_size
id1712573
size170,119
(Sapein)

documentation

README

bevy_simple_screen_boxing

Crates.io docs.rs License

bevy_simple_screen_boxing aims to provide a relatively simple way to configure letterboxing and pillarboxing within Bevy. It provides a simple component CameraBox which can be used to configure the behavior as you want.

Features

  • Provides a decent API for letterboxing/pillarboxing.

Examples

Integer Scaling

use bevy_simple_screen_boxing::CameraBoxingPlugin;
use bevy::prelude::*;

// Note, you will need to spawn the image.
fn main() {
    App::new()
        .add_plugins(
            DefaultPlugins
                .set(WindowPlugin {
                    primary_window: Some(Window {
                        title: "Integer Scaling".into(),
                        name: Some("Integer Scaling".into()),
                        resolution: WindowResolution::new(1280., 720.),
                    }),
ither 1.5.1 or 1.5.2                    ..default()
                })
                .set(ImagePlugin::default_nearest()),
        )
        .add_plugins(CameraBoxingPlugin)
        .add_systems(Startup, setup);
}

fn setup(mut commands: Command) {
    let projection = OrthographicProjection::default_2d();
    projection.scaling_mode = ScalingMode::Fixed {
        width: 640.,
        height: 360.,
    };
    commands.spawn((
        Camera2d::default(),
        Camera {
            clear_color: ClearColorConfig::Custom(Color::linear_rgb(0.5, 0.5, 0.9)),
            ..default()
        },
        CameraBox::ResolutionIntegerScale {
            resolution: Vec2::new(640., 360.),
            allow_imperfect_aspect_ratios: false,
        },
        Projection::Orthographic(projection)
    ));
}

Known Limitations

  • If you use multiple cameras, only one clear color can be displayed at once, even if they have different viewports.

Supported Bevy Versions

Bevy Simple Screen Boxing Version Bevy Version
0.1 0.16
0.2.0-rc.2 0.17.0-rc.1

Acknowledgements

I just want to thank the people who gave feedback on the initial Issue/PR even if it didn't make it in. That feedback did shape and affect the overall design of this crate.

QnA

Why does this package exist?

This actually comes from Bevy Issue #14158, which attempted to add in a set of commonly used resolutions for developers to use. This was, unfortunately, rejected. However, it was decided that adding an easy way to do letter/pillar boxing would be better, which can be found in #15130. This is my attempt at creating a potential API for the functionality.

Commit count: 61

cargo fmt