Skip to content

Commit

Permalink
Add pixelated Bevy to assets and an example (bevyengine#6408)
Browse files Browse the repository at this point in the history
# Objective
Fixes bevyengine#2279 

## Solution
Added pixelated Bevy to assets folder and used in a `pixel_perfect` example.
  • Loading branch information
ong-yy authored and ItsDoot committed Feb 1, 2023
1 parent 5ffa689 commit 0b8e71f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Binary file added assets/pixel/bevy_pixel_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/pixel/bevy_pixel_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions examples/2d/pixel_perfect.rs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0b8e71f

Please sign in to comment.