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(
|
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>>,
|
keyboard_input: Res<Input<KeyCode>>,
|
||||||
mut app_exit_events: ResMut<Events<bevy::app::AppExit>>,
|
mut app_exit_events: ResMut<Events<bevy::app::AppExit>>,
|
||||||
|
texture_atlases: Res<Assets<TextureAtlas>>,
|
||||||
) {
|
) {
|
||||||
if keyboard_input.pressed(KeyCode::Escape) {
|
if keyboard_input.pressed(KeyCode::Escape) {
|
||||||
app_exit_events.send(bevy::app::AppExit);
|
app_exit_events.send(bevy::app::AppExit);
|
||||||
} else if keyboard_input.pressed(KeyCode::N) {
|
} else if keyboard_input.just_pressed(KeyCode::N) {
|
||||||
let mut sprite = query.single_mut();
|
let (texture, mut sprite) = query.single_mut();
|
||||||
sprite.index += 1;
|
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