use bevy::prelude::*; fn main() { App::build() .add_plugin_group(DefaultPlugins) .add_startup_system(setup.system()) .add_system(animate_sprite_system.system()) .run(); } fn animate_sprite_system( texture_atlases: Res>, mut query: Query<(&mut Timer, &mut TextureAtlasSprite, &Handle)>, ) { for (timer, mut sprite, texture_atlas_handle) in query.iter_mut() { if timer.finished { let texture_atlas = texture_atlases.get(texture_atlas_handle).unwrap(); sprite.index = ((sprite.index as usize + 1) % texture_atlas.textures.len()) as u32; } } } fn setup( mut commands: Commands, asset_server: Res, mut texture_atlases: ResMut>, ) { let texture_handle = asset_server.load("textures/rpg/chars/gabe/gabe-idle-run.png"); let texture_atlas = TextureAtlas::from_grid(texture_handle, Vec2::new(24.0, 24.0), 7, 1); let texture_atlas_handle = texture_atlases.add(texture_atlas); commands .spawn(Camera2dComponents::default()) .spawn(SpriteSheetComponents { texture_atlas: texture_atlas_handle, transform: Transform::from_scale(Vec3::splat(6.0)), ..Default::default() }) .with(Timer::from_seconds(0.1, true)); }