Pixel Camera
A simple set of coponents, schedules, systems and helper functions to create any type of pixel camera
NOTE this is a work in progress, and if you have any feedback feel free to open an issue or pull request
Usage
The following example shows a simple usage of the libary. This example utilises the PixelCameraSnapping
and PixelCanvasSmoothing components to make it appear as if the the objects themselves are pixelated rather
than the camera. Yet if you want the retro style feel you can ommit the components
use bevy::{
prelude::*,
render::{camera::ScalingMode, view::RenderLayers},
};
use pixel_camera::prelude::*;
fn main() {
App::new()
.add_plugins((DefaultPlugins, PixelCameraPlugin) .add_systems(Startup, setup)
.run();
}
pub const PIXELS_PER_UNIT: f32 = 8.0;
pub const HIGH_RES_LAYER: RenderLayers = RenderLayers::layer(0);
pub const PIXEL_PERFECT_LAYER: RenderLayers = RenderLayers::layer(1);
#[derive(Component)]
pub struct MainCamera;
pub fn setup_cameras(mut commands: Commands, images: ResMut<Assets<Image>>) {
let mut cam_2d = Camera2dBundle::default();
cam_2d.projection.scaling_mode = ScalingMode::AutoMin {
min_width: 16.0,
min_height: 8.0,
};
let main_cam = commands
.spawn((cam_2d, HIGH_RES_LAYER, MainCamera))
.id();
let image = create_pixel_image(images);
let pixel_camera = create_pixel_camera(commands.reborrow(), image.clone(), PIXEL_PERFECT_LAYER);
let pixel_canvas = create_pixel_canvas(
&PixelCanvasConfig::new(PIXELS_PER_UNIT, 8.0, 4.0),
commands.reborrow(),
image,
pixel_camera,
HIGH_RES_LAYER,
);
commands.entity(pixel_camera).insert(PixelCameraSnapping);
commands.entity(pixel_canvas).insert(PixelCanvasSmoothing);
}