package ecs.systems;

import ecs.components.Spatial;
import ecs.components.Sprite;
import ecs.core.System;
import res.display.FrameBuffer;

using Std;

class DrawSpriteSystem extends System {
	public function new() {
		super(Spatial, Sprite);

		updatable = false;
	}

	override public function render(frameBuffer:FrameBuffer) {
		for (entity in entities) {
			final sprite = entity.get(Sprite);
			final spatial = entity.get(Spatial);

			res.display.Sprite.drawSprite(frameBuffer, sprite.sprite, (spatial.x - sprite.sprite.width * sprite.anchorX).int(),
				(spatial.y - sprite.sprite.height * sprite.anchorY).int(), sprite.flipX, sprite.flipY, sprite.wrap);
		}
	}
}
