123456789101112131415161718192021222324252627282930313233343536373839404142 |
- use crate::consts;
- use crate::components::{Position,Sprite};
- use ggez::{
- Context,
- graphics::spritebatch::SpriteBatch,
- };
- use ggez::graphics;
- pub struct Draw<'t, Phase> {
- pub ctx: &'t mut Context,
- pub sprites: &'t mut SpriteBatch,
- pub _phase: Phase,
- }
- impl<'a, 't, Phase: specs::Component> specs::System<'a> for Draw<'t, Phase> {
- type SystemData = (
- specs::ReadStorage<'a, Position>,
- specs::ReadStorage<'a, Sprite>,
- specs::ReadStorage<'a, Phase>,
- );
- fn run(&mut self, (positions, sprites, phase): Self::SystemData) {
- use specs::Join;
- for (pos, spr, _) in (&positions, &sprites, &phase).join() {
- let param = graphics::DrawParam {
- src: spr.to_rect(),
- dest: pos.to_point(),
- scale: ggez::nalgebra::Point2::new(consts::SCALE, consts::SCALE),
- ..Default::default()
- };
- self.sprites.add(param);
- graphics::draw(
- self.ctx,
- self.sprites,
- ggez::nalgebra::Point2::new(0.0, 0.0),
- 0.0).unwrap();
- self.sprites.clear();
- }
- }
- }
|