首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

技艺冷却动画转圈圈

2012-12-24 
技能冷却动画转圈圈方法一:package ui{import flash.display.Graphicsimport flash.display.Spriteimpor

技能冷却动画转圈圈

方法一:
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:Spriteprivate 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;}}
?

热点排行