Crates.io | bevy_modern_pixel_camera |
lib.rs | bevy_modern_pixel_camera |
version | |
source | src |
created_at | 2024-10-26 12:28:54.325154 |
updated_at | 2024-11-30 14:41:11.489461 |
description | A simple pixel-perfect camera plugin for Bevy, suitable for pixel-art |
homepage | |
repository | https://github.com/ironpeak/bevy_modern_pixel_camera |
max_upload_size | |
id | 1423820 |
Cargo.toml error: | TOML parse error at line 25, column 1 | 25 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Based of: https://github.com/drakmaniso/bevy_pixel_camera
A simple camera plugin for the Bevy game engine, to help with the use of pixel-art sprites.
This crates provides a plugin to automatically configure Bevy's
Camera2dBundle
. It works by setting the camera to an integer scaling
factor (using Bevy's ScalingMode::WindowSize
), and automatically updating
the zoom level so that the specified target resolution fills as much of the
sceen as possible.
The plugin can also automatically set and resize the viewport of the camera to match the target resolution.
Note that Bevy uses linear sampling by default for textures, which is not
what you want for pixel art. The easiest way to change this is to configure
Bevy's default plugins with ImagePlugin::default_nearest()
.
Note that Bevy uses MSAA
by default for textures, which is not what you want for pixel art The easiest way
to change this is to configure Bevy's by overriding the Msaa resource with
.insert_resource(Msaa::Off)
.
Also note that if either the width or the height of your sprite is not divisible by 2, you may need to change the anchor of the sprite (which is at the center by default), otherwise it won't be aligned with virtual pixels.
use bevy::prelude::*;
use bevy::sprite::Anchor;
use bevy_modern_pixel_camera::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()))
.add_plugins(PixelCameraPlugin)
.insert_resource(Msaa::Off)
.add_systems(Startup, setup)
.run();
}
fn setup(
mut commands: Commands,
asset_server: Res<AssetServer>,
) {
commands.spawn((
Camera2dBundle::default(),
PixelZoom::FitSize {
width: 320,
height: 180,
},
PixelViewport,
));
commands.spawn(SpriteBundle {
texture: asset_server.load("my-pixel-art-sprite.png"),
sprite: Sprite {
anchor: Anchor::BottomLeft,
..Default::default()
},
..Default::default()
});
}
A small example is included in the crate. Run it with:
cargo run --example mire
bevy | bevy_modern_pixel_camera |
---|---|
0.15 | 0.2 |
0.14 | 0.1 |
Licensed under either of
at your option.
License: MIT OR Apache-2.0