drawing.rs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. use crate::consts;
  2. use crate::components::{Position,Sprite};
  3. use ggez::{
  4. Context,
  5. graphics::spritebatch::SpriteBatch,
  6. };
  7. use ggez::graphics;
  8. pub struct Draw<'t, Phase> {
  9. pub ctx: &'t mut Context,
  10. pub sprites: &'t mut SpriteBatch,
  11. pub _phase: Phase,
  12. }
  13. impl<'a, 't, Phase: specs::Component> specs::System<'a> for Draw<'t, Phase> {
  14. type SystemData = (
  15. specs::ReadStorage<'a, Position>,
  16. specs::ReadStorage<'a, Sprite>,
  17. specs::ReadStorage<'a, Phase>,
  18. );
  19. fn run(&mut self, (positions, sprites, phase): Self::SystemData) {
  20. use specs::Join;
  21. for (pos, spr, _) in (&positions, &sprites, &phase).join() {
  22. let param = graphics::DrawParam {
  23. src: spr.to_rect(),
  24. dest: pos.to_point(),
  25. scale: ggez::nalgebra::Point2::new(consts::SCALE, consts::SCALE),
  26. ..Default::default()
  27. };
  28. self.sprites.add(param);
  29. graphics::draw(
  30. self.ctx,
  31. self.sprites,
  32. ggez::nalgebra::Point2::new(0.0, 0.0),
  33. 0.0).unwrap();
  34. self.sprites.clear();
  35. }
  36. }
  37. }