Skip to content

Commit

Permalink
Updated many_animated_sprites_example
Browse files Browse the repository at this point in the history
  • Loading branch information
ManevilleF committed Aug 9, 2022
1 parent dda41fb commit 344e435
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions examples/stress_tests/many_animated_sprites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn setup(
let half_y = (map_size.y / 2.0) as i32;

let texture_handle = assets.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 = TextureAtlas::from_grid(Vec2::new(24.0, 24.0), 7, 1);
let texture_atlas_handle = texture_atlases.add(texture_atlas);

// Spawns the camera
Expand All @@ -67,13 +67,17 @@ fn setup(

commands
.spawn_bundle(SpriteSheetBundle {
texture_atlas: texture_atlas_handle.clone(),
texture: texture_handle.clone(),
sheet: TextureSheet {
texture_atlas: texture_atlas_handle.clone(),
..Default::default()
},
transform: Transform {
translation,
rotation,
scale,
},
sprite: TextureAtlasSprite {
sprite: Sprite {
custom_size: Some(tile_size),
..default()
},
Expand All @@ -98,17 +102,13 @@ struct AnimationTimer(Timer);
fn animate_sprite(
time: Res<Time>,
texture_atlases: Res<Assets<TextureAtlas>>,
mut query: Query<(
&mut AnimationTimer,
&mut TextureAtlasSprite,
&Handle<TextureAtlas>,
)>,
mut query: Query<(&mut AnimationTimer, &mut TextureSheet)>,
) {
for (mut timer, mut sprite, texture_atlas_handle) in query.iter_mut() {
for (mut timer, mut sheet) in query.iter_mut() {
timer.tick(time.delta());
if timer.just_finished() {
let texture_atlas = texture_atlases.get(texture_atlas_handle).unwrap();
sprite.index = (sprite.index + 1) % texture_atlas.textures.len();
let texture_atlas = texture_atlases.get(&sheet.texture_atlas).unwrap();
sheet.texture_index = (sheet.texture_index + 1) % texture_atlas.textures.len();
}
}
}
Expand All @@ -123,11 +123,7 @@ impl Default for PrintingTimer {
}

// System for printing the number of sprites on every tick of the timer
fn print_sprite_count(
time: Res<Time>,
mut timer: Local<PrintingTimer>,
sprites: Query<&TextureAtlasSprite>,
) {
fn print_sprite_count(time: Res<Time>, mut timer: Local<PrintingTimer>, sprites: Query<&Sprite>) {
timer.tick(time.delta());

if timer.just_finished() {
Expand Down

0 comments on commit 344e435

Please sign in to comment.