diff --git a/Cargo.toml b/Cargo.toml index f4c6f3f9f9037..d20859cdd2e3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -262,6 +262,16 @@ description = "Demonstrates transparency in 2d" category = "2D Rendering" wasm = true +[[example]] +name = "pixel_perfect" +path = "examples/2d/pixel_perfect.rs" + +[package.metadata.example.pixel_perfect] +name = "Pixel Perfect" +description = "Demonstrates pixel perfect in 2d" +category = "2D Rendering" +wasm = true + # 3D Rendering [[example]] name = "3d_scene" diff --git a/assets/pixel/bevy_pixel_dark.png b/assets/pixel/bevy_pixel_dark.png new file mode 100644 index 0000000000000..15feaa9460329 Binary files /dev/null and b/assets/pixel/bevy_pixel_dark.png differ diff --git a/assets/pixel/bevy_pixel_light.png b/assets/pixel/bevy_pixel_light.png new file mode 100644 index 0000000000000..f6225fe25eabb Binary files /dev/null and b/assets/pixel/bevy_pixel_light.png differ diff --git a/examples/2d/pixel_perfect.rs b/examples/2d/pixel_perfect.rs new file mode 100644 index 0000000000000..cce3d6135fa30 --- /dev/null +++ b/examples/2d/pixel_perfect.rs @@ -0,0 +1,44 @@ +//! Renders a 2D scene containing pixelated bevy logo in a pixel perfect style + +use bevy::prelude::*; + +fn main() { + App::new() + .add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest())) + .add_startup_system(setup) + .add_system(sprite_movement) + .run(); +} + +#[derive(Component)] +enum Direction { + Left, + Right, +} + +fn setup(mut commands: Commands, asset_server: Res) { + commands.spawn(Camera2dBundle::default()); + commands.spawn(( + SpriteBundle { + texture: asset_server.load("pixel/bevy_pixel_light.png"), + transform: Transform::from_xyz(100., 0., 0.), + ..default() + }, + Direction::Right, + )); +} + +fn sprite_movement(time: Res