Sprite frame cycling
This commit is contained in:
parent
d851eb7676
commit
27c58b569e
16
src/main.rs
16
src/main.rs
|
@ -36,14 +36,22 @@ fn main() {
|
|||
}
|
||||
|
||||
fn keyboard_input_system(
|
||||
mut query: Query<&mut TextureAtlasSprite, With<player::Player>>,
|
||||
mut query: Query<(&Handle<TextureAtlas>, &mut TextureAtlasSprite), With<player::Player>>,
|
||||
keyboard_input: Res<Input<KeyCode>>,
|
||||
mut app_exit_events: ResMut<Events<bevy::app::AppExit>>,
|
||||
texture_atlases: Res<Assets<TextureAtlas>>,
|
||||
) {
|
||||
if keyboard_input.pressed(KeyCode::Escape) {
|
||||
app_exit_events.send(bevy::app::AppExit);
|
||||
} else if keyboard_input.pressed(KeyCode::N) {
|
||||
let mut sprite = query.single_mut();
|
||||
sprite.index += 1;
|
||||
} else if keyboard_input.just_pressed(KeyCode::N) {
|
||||
let (texture, mut sprite) = query.single_mut();
|
||||
let t = texture_atlases
|
||||
.get(texture)
|
||||
.expect("could not load player texture");
|
||||
if sprite.index < t.textures.len() - 1 {
|
||||
sprite.index += 1;
|
||||
} else {
|
||||
sprite.index = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue