Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233
  1. use specs::prelude::*;
  2. use crate::components::*;
  3. pub struct Animator;
  4. impl<'a> System<'a> for Animator {
  5. type SystemData = (
  6. WriteStorage<'a, MovementAnimation>,
  7. WriteStorage<'a, Sprite>,
  8. ReadStorage<'a, Velocity>,
  9. );
  10. fn run(&mut self, mut data: Self::SystemData) {
  11. use self::Direction::*;
  12. for (anim, sprite, vel) in (&mut data.0, &mut data.1, &data.2).join() {
  13. if vel.speed == 0 {
  14. continue;
  15. }
  16. let frames = match vel.direction {
  17. Left => &anim.left_frames,
  18. Right => &anim.right_frames,
  19. Up => &anim.up_frames,
  20. Down => &anim.down_frames,
  21. };
  22. anim.current_frame = (anim.current_frame + 1) % frames.len();
  23. *sprite = frames[anim.current_frame].clone();
  24. }
  25. }
  26. }