package  
{
	import net.flashpunk.Entity;
	import net.flashpunk.graphics.Text;
	import net.flashpunk.FP;
	
	/**
	 * ...
	 * @author Benn
	 */
	public class HudText extends Entity 
	{
		
		[Embed(source='../assets/graphics/orbitron-medium.otf', embedAsCFF="false", fontFamily = 'Orbitron')] private static const ORBITRON_FONT:Class;
		
		private var MyText:Text;
		
		private var FadeTimer:Number = 1;
		private var IsFadingOut:Boolean = false;
		private var IsFadingIn:Boolean = false;
		
		public function HudText(value:String) 
		{
			MyText = new Text(value);
		
			MyText.font = 'Orbitron';
			MyText.color = 0x000000;
			MyText.size = 20;
			
			graphic = MyText;
		}
		
		public function SetColour(value:uint):void
		{
			MyText.color = value;
		}
		
		public function IsVisible():Boolean
		{
			return (MyText.alpha > 0);
		}
		
		public function SetText(value:String):void
		{
			MyText.text = value;
		}
		
		public function GetText():String
		{
			return MyText.text.toString();
		}
		
		public function SetSize(value:int):void
		{
			MyText.size = value;
		}
		
		public function FadeIn():void
		{
			MyText.alpha = 0;
			IsFadingIn = true;
		}
		
		public function FadeOut():void
		{
			IsFadingOut = true;
		}
		
		override public function update():void 
		{
			
			if (IsFadingOut)
			{
				
				FadeTimer -= FP.elapsed;
				
				MyText.alpha = FadeTimer;
				
				if (FadeTimer < 0)
				{
					FadeTimer = 1;
					MyText.alpha = 0;
					IsFadingOut = false;
				}
				
			}
			else if (IsFadingIn)
			{
				FadeTimer -= FP.elapsed;
				
				MyText.alpha = 1 - FadeTimer;
				
				if (FadeTimer < 0)
				{
					FadeTimer = 1;
					MyText.alpha = 1;
					IsFadingIn = false;
				}
			}
			
			super.update();
		}
		
	}

}