Skip to main content

Crate bevy_smooth_pixel_camera

Crate bevy_smooth_pixel_camera 

Source
Expand description

A bevy plugin that adds a simple smooth pixel camera.

It works by rendering the main camera to a small viewport which is then rendered by a second camera spawned by the plugin. This allows for hybrid rendering of both a pixelated world and high resolution assets on top.

This plugin has a smoothing feature, which makes the camera’s movement appear smooth while keeping the world itself locked to a pixel grid. It works by moving the canvas in the opposite direction of the world camera’s subpixel position. See the how_smoothing_works example for a demonstration of how it works behind the scenes.

Smoothing OFFSmoothing ON
The camera is locked to the pixel grid, causing jagged motionThe camera moves smoothly while the world itself stays locked to a pixel grid.

§Usage

  1. Add the bevy_smooth_pixel_camera crate to your project.

    cargo add bevy_smooth_pixel_camera
  2. Add the PixelCameraPlugin and set ImagePlugin to default_nearest.

    use bevy::prelude::*;
    use bevy_smooth_pixel_camera::prelude::*;
     
    App::new()
        .add_plugins((
            DefaultPlugins.set(ImagePlugin::default_nearest()),
            PixelCameraPlugin,
        ))
        .run();
  3. Add a PixelCamera to your world.

    use bevy::prelude::*;
    use bevy_smooth_pixel_camera::prelude::*;
    
    fn setup(mut commands: Commands) {
        commands.spawn(PixelCamera::from_size(ViewportScalingMode::PixelSize(4.0)));
    }
  4. That’s it!

§Features

picking (default) - Enables picking through the viewport.

§Bevy Compatibility

bevybevy_smooth_pixel_camera
0.18.*0.4.x - main
0.13.*0.3.0
0.12.*0.1.0 - 0.2.1

Modules§

components
The components of bevy_smooth_pixel_camera.
prelude
use bevy_smooth_pixel_camera::prelude::*; to import PixelCamera and PixelCameraPlugin, among other things.
viewport
Viewport Scaling and Stretching.

Structs§

PixelCameraPlugin
Updates the PixelCamera, allowing for smoothing, the viewport resizing with the window, and picking.

Enums§

CameraSystems
A SystemSet for PixelCameraPlugin’s systems.

Constants§

CAMERA_POSITION_OFFSET
A tiny offset applied to the PixelCamera’s final position every frame.