mirror of
https://github.com/bevyengine/bevy
synced 2024-11-13 00:17:27 +00:00
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:
parent
308e092153
commit
dc09ee36e2
5 changed files with 55 additions and 0 deletions
10
Cargo.toml
10
Cargo.toml
|
@ -262,6 +262,16 @@ description = "Demonstrates transparency in 2d"
|
||||||
category = "2D Rendering"
|
category = "2D Rendering"
|
||||||
wasm = true
|
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
|
# 3D Rendering
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "3d_scene"
|
name = "3d_scene"
|
||||||
|
|
BIN
assets/pixel/bevy_pixel_dark.png
Normal file
BIN
assets/pixel/bevy_pixel_dark.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.8 KiB |
BIN
assets/pixel/bevy_pixel_light.png
Normal file
BIN
assets/pixel/bevy_pixel_light.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 182 B |
44
examples/2d/pixel_perfect.rs
Normal file
44
examples/2d/pixel_perfect.rs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -93,6 +93,7 @@ Example | Description
|
||||||
[Mesh 2D](../examples/2d/mesh2d.rs) | Renders a 2d mesh
|
[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
|
[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
|
[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](../examples/2d/sprite.rs) | Renders a sprite
|
||||||
[Sprite Flipping](../examples/2d/sprite_flipping.rs) | Renders a sprite flipped along an axis
|
[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
|
[Sprite Sheet](../examples/2d/sprite_sheet.rs) | Renders an animated sprite
|
||||||
|
|
Loading…
Reference in a new issue