forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pixelated Bevy to assets and an example (bevyengine#6408)
# Objective Fixes bevyengine#2279 ## Solution Added pixelated Bevy to assets folder and used in a `pixel_perfect` example.
- Loading branch information
Showing
5 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters