package Engine
{
	import Engine.GameSprite;
	import flash.display.BitmapData;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	
	
	/**
	 * ...
	 * @author ...
	 */
	public class SpriteEngine extends SpriteGroup
	{
		public var Buffer:BitmapData;
		
		override public function get width():uint
		{
			return Buffer.width;
		}
		
		override public function get height():uint
		{
			return Buffer.height;
		}
		
		override public function get Rect():Rectangle
		{
			return Buffer.rect;
		}
		
		override public function AddSprite(newSprite:GameSprite):void
		{
			super.AddSprite(newSprite);
			if (newSprite is SpriteGroup) {
				SpriteGroup(newSprite).Group = this;
				SpriteGroup(newSprite).SetClipRect(Rect);
			}
		}
		
		/**
		 * Прорисовка всех имеющихся спрайтов во временный буфер
		 */
		public function DrawBuffer():void {
			Buffer.fillRect(Buffer.rect, 0);
			
			prepareSprites();
			
			for (var i:uint = 0; i < Sprites.length; i++) {
				(Sprites[i] as GameSprite).Draw(Buffer);
				(Sprites[i] as GameSprite).Drawed = true;
			}
		}
		
		public function InitSurface(displayW:uint, displayH:uint):void {
			Buffer = new BitmapData(displayW, displayH);
		}
		
		/**
		 * Конструктор
		 */
		public function SpriteEngine() {
			
		}
		
	}

}