技能冷却动画转圈圈

方法一:
package ui
{
        import flash.display.Graphics;
        import flash.display.Sprite;
        import flash.events.Event;
        import flash.geom.Point;
        import flash.utils.getTimer;
        /**
         * 
         * @author whh
         * 
         * 用法:
         * duration:旋转一圈需要时间
         * length:圆的半径
         * start()开始
         * 
         * 如:
         * var a:Circle = new Circle()
         * a.duration = 20000;
         * a.start();
         */        
        public class Circle extends Sprite
        {
                public function Circle()
                {
                        graph = this.graphics;
                        tempPoint = new Point(0,-length);
                }
                
                public var duration:int;
                public var length:int = 20;
                private var tempPoint : Point
                private var graph:Graphics;
                private var startTime:int;
                public function start():void
                {
                        graph.clear();
                        startTime = getTimer();
                        this.addEventListener(Event.ENTER_FRAME,enterFrameHandler);
                }
                
                private function enterFrameHandler(event:Event):void
                {
                        var t:Number = getTimer() - startTime;
                        if(t>duration)
                        {
                                this.removeEventListener(Event.ENTER_FRAME,enterFrameHandler);
                                draw(360);
                                return;
                        }
                        draw(t/duration * 360);
                }
                
                private function draw(angle:Number):void
                {
                        var temp:Number = (angle-90)*Math.PI/180;
                        graph.beginFill(0xFF0000);
                        var ca:Number = Math.cos(temp)*length;
                        var sa:Number = Math.sin(temp)*length;
                        graph.moveTo(0,0);
                        graph.lineTo(tempPoint.x,tempPoint.y);
                        graph.lineTo(ca,sa);
                        graph.lineTo(0,0);
                        tempPoint.x = ca;
                        tempPoint.y = sa;
                        graph.endFill();
                }

        }
}

 方法二:

	private var cool:Sprite;
		private var sector:Sprite
		private var timerId:int;
		private var timeCount:int;
		private var angle:int;
		private var timeSpace:int;
		public var coolStatus:Boolean;

		/**
		 * 设置冷却时间
		 *
		 */
		public function setCool(time:int=2000):void
		{
			if (_lock)
				return;
			if (!cool)
			{
				cool=new Sprite();
				sector=new Sprite();
			}
			addChild(cool);
			addChild(sector);
			cool.graphics.clear();
			cool.graphics.beginFill(0xff0000, 0.5);
			cool.graphics.drawRect(0, 0, this.width, this.height);
			cool.graphics.endFill();
			angle=0;
			timeCount=time;
			timeSpace=time / 30;
			timerId=CatchSetInterval(coolCal, timeSpace);
			coolStatus=true;
		}


		private function coolCal():void
		{
			sector.graphics.clear();
			timeCount-=timeSpace;
			angle+=12;
			Tools.DrawHPMPSector(sector, this.width / 2, this.height / 2, 25, 360 - angle, 270 + angle);
			cool.mask=sector;
			dragFrom=false;
			if (timeCount <= 0)
			{
				clearInterval(timerId);
				removeChild(cool);
				removeChild(sector);
				dragFrom=true;
				coolStatus=false;
			}
		}
 

你可能感兴趣的:(UI,Flash,360)