Add pixelated Bevy to assets and an example (#6408)

# Objective
Fixes #2279 

## Solution
Added pixelated Bevy to assets folder and used in a `pixel_perfect` example.
This commit is contained in:
Yyee 2022-11-14 22:15:46 +00:00
parent 308e092153
commit dc09ee36e2
5 changed files with 55 additions and 0 deletions

View file

@ -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"

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

View file

@ -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<AssetServer>) {
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<Time>, mut sprite_position: Query<(&mut Direction, &mut Transform)>) {
for (mut logo, mut transform) in &mut sprite_position {
match *logo {
Direction::Right => transform.translation.x += 30. * time.delta_seconds(),
Direction::Left => transform.translation.x -= 30. * time.delta_seconds(),
}
if transform.translation.x > 200. {
*logo = Direction::Left;
} else if transform.translation.x < -200. {
*logo = Direction::Right;
}
}
}

View file

@ -93,6 +93,7 @@ Example | Description
[Mesh 2D](../examples/2d/mesh2d.rs) | Renders a 2d mesh
[Mesh 2D With Vertex Colors](../examples/2d/mesh2d_vertex_color_texture.rs) | Renders a 2d mesh with vertex color attributes
[Move Sprite](../examples/2d/move_sprite.rs) | Changes the transform of a sprite
[Pixel Perfect](../examples/2d/pixel_perfect.rs) | Demonstrates pixel perfect in 2d
[Sprite](../examples/2d/sprite.rs) | Renders a sprite
[Sprite Flipping](../examples/2d/sprite_flipping.rs) | Renders a sprite flipped along an axis
[Sprite Sheet](../examples/2d/sprite_sheet.rs) | Renders an animated sprite