技能冷却效果...

http://btbtd.org/topic/flash/DrawRectCircle/Main.swf

http://btbtd.org/topic/flash/DrawRectCircle/DrawRectCircle.zip
  1. package  
  2. {
  3.         import flash.display.Sprite;
  4.         import flash.utils.Timer;
  5.         import flash.events.TimerEvent;
  6.         public class DrawRectCircle extends Sprite
  7.         {
  8.         private var shadow:Sprite;
  9.         
  10.         private var xMinPoint:Number = 0;
  11.         private var xMidPoint:Number = 0;
  12.         private var xMaxPoint:Number = 0;
  13.         
  14.         private var yMinPoint:Number = 0;
  15.         private var yMidPoint:Number = 0;
  16.         private var yMaxPoint:Number = 0;
  17.         
  18.         private var runAllMs:Number = 1000;
  19.         private var stepMs:Number = 0;
  20.         
  21.         private var timer:Timer;
  22.         private var percentCount:Number = 0;
  23.         
  24.        
  25.                 public function DrawRectCircle( pX:int = 0, pY:int = 0 )
  26.                 {
  27.             this.x = pX;
  28.             this.y = pY;
  29.                                     
  30.             shadow = new Sprite();
  31.             addChild( shadow );
  32.                 }
  33.                
  34.                 public function get getTimer():Timer
  35.                 {
  36.             return this.timer;
  37.         }
  38.                
  39.                 public function drawCircle( pWidth:int = 50, pHeight:int = 50 ):void
  40.                 {   
  41.             this.graphics.clear();                       
  42.             this.graphics.lineStyle( 0, 0, 0 );
  43.             this.graphics.beginFill( 0x000000, .1 );
  44.             this.graphics.drawRect( 0, 0, pWidth, pHeight );
  45.             this.graphics.endFill();
  46.             
  47.             this.xMidPoint = pWidth / 2;
  48.             this.xMaxPoint = pWidth;
  49.             
  50.             this.yMidPoint = pHeight / 2;
  51.             this.yMaxPoint = pHeight;
  52.             
  53.             
  54.             stepMs = runAllMs / 25;
  55.             
  56.             if( timer )
  57.             {
  58.                 if( timer.running )
  59.                 {
  60.                     timer.stop();
  61.                     timer.removeEventListener( TimerEvent.TIMER, onTimerEvent );
  62.                     timer = null;
  63.                 }
  64.             }
  65.             
  66.             percentCount = 0;
  67.             
  68.             timer = new Timer( stepMs )
  69.             timer.addEventListener( TimerEvent.TIMER, onTimerEvent );
  70.             timer.start();
  71.             
  72.             //makeGraphic();
  73.             
  74.         }
  75.         
  76.         private function onTimerEvent( event:TimerEvent ):void
  77.         {
  78.             percentCount += 4;
  79.             
  80.             if( percentCount > 100 )
  81.             {
  82.                 timer.stop();
  83.                 return;
  84.             }
  85.             
  86.             makeGraphic( percentCount );
  87.             
  88.             event.updateAfterEvent();
  89.         }
  90.         
  91.         private function getPoint( knowPoint:Number, degree:Number, midPoint:Number = 0 ):Number
  92.         {
  93.             if( !midPoint)
  94.             {
  95.                 midPoint = xMidPoint;
  96.             }
  97.             var result:Number = knowPoint + (degree % 45) / 45 * midPoint;
  98.             return result;
  99.         }
  100.         
  101.          
  102.         /*
  103.             var degree:Number = percent / 100 * 360;
  104.             var percent:Number 100 / 360 * 60;
  105.             var point:Number = xMidPoint + (degree % 45) / 45 * xMidPoint;
  106.         */   
  107.         private function makeGraphic( percent:Number = 0 ):void
  108.         {
  109.             var degree:Number = percent / 100 * 360;        
  110.             
  111.             //degree = 230.4;
  112.             
  113.             var temp:Number = 0;
  114.             
  115.             shadow.graphics.clear();
  116.             shadow.graphics.lineStyle( 0, 0, 0 );
  117.             shadow.graphics.beginFill( 0x000000, .35 );
  118.             
  119.             shadow.graphics.moveTo( xMidPoint, yMidPoint )
  120.             
  121.             trace( 'degree: ' + degree +', '+( degree % 45 ) )
  122.             
  123.             if( degree > 0 && degree < 45 )
  124.             {               
  125.                 shadow.graphics.lineTo( xMidPoint, 0 );
  126.                
  127.                 shadow.graphics.lineTo( getPoint(xMidPoint, degree), 0 );
  128.             }
  129.             
  130.             if( degree >= 45 )
  131.             {
  132.                 shadow.graphics.lineTo( xMidPoint, 0 );
  133.                 shadow.graphics.lineTo( xMaxPoint, 0 );
  134.                
  135.                 if( degree > 45 && degree < 90 )
  136.                 {
  137.                     shadow.graphics.lineTo( xMaxPoint, getPoint(0, degree, yMidPoint) );
  138.                 }      
  139.             }
  140.             
  141.             if( degree >= 90 )
  142.             {
  143.                 shadow.graphics.lineTo( xMaxPoint, yMidPoint );   
  144.                
  145.                 if( degree > 90 && degree < 135 )
  146.                 {
  147.                     shadow.graphics.lineTo( xMaxPoint, getPoint(yMidPoint, degree, yMidPoint) );
  148.                 }           
  149.             }   
  150.             
  151.             if( degree >= 135 )
  152.             {
  153.                 shadow.graphics.lineTo( xMaxPoint, yMaxPoint );
  154.                
  155.                 if( degree > 135 && degree < 180 )
  156.                 {
  157.                     shadow.graphics.lineTo( xMaxPoint - getPoint(xMidPoint, degree) + xMidPoint, yMaxPoint );
  158.                 }         
  159.             }      
  160.             
  161.             if( degree >= 180 )
  162.             {
  163.                 shadow.graphics.lineTo( xMidPoint, yMaxPoint );
  164.                
  165.                 if( degree > 180 && degree < 225 )
  166.                 {
  167.                     shadow.graphics.lineTo( xMaxPoint - getPoint(xMidPoint, degree), yMaxPoint );
  168.                 }      
  169.             }
  170.             
  171.             if( degree >= 225 )
  172.             {
  173.                 shadow.graphics.lineTo( 0, yMaxPoint );
  174.                
  175.                 if( degree > 225 && degree < 270 )
  176.                 {
  177.                     shadow.graphics.lineTo( 0, yMaxPoint - getPoint(yMidPoint, degree, yMidPoint) + yMidPoint );
  178.                 }      
  179.             }   
  180.             
  181.             if( degree >= 270 )
  182.             {
  183.                 shadow.graphics.lineTo( 0, yMidPoint );
  184.                
  185.                 if( degree > 270 && degree < 315 )
  186.                 {
  187.                     shadow.graphics.lineTo( 0, yMaxPoint - getPoint(yMidPoint, degree, yMidPoint) );
  188.                 }   
  189.             }     
  190.             
  191.             if( degree >= 315 )
  192.             {
  193.                 shadow.graphics.lineTo( 0, 0 );
  194.                
  195.                 if( degree > 315 && degree < 360 )
  196.                 {
  197.                     shadow.graphics.lineTo( getPoint(0, degree), 0 );
  198.                 }   
  199.             }     
  200.             
  201.             if( degree >= 360 )
  202.             {
  203.                 shadow.graphics.lineTo( xMidPoint, 0 );
  204.             }      
  205.             
  206.             shadow.graphics.lineTo( xMidPoint, yMidPoint );
  207.             shadow.graphics.endFill();     
  208.         }
  209.        
  210.         }
  211.        
  212. }
posted @ 2011-02-18 17:48  as爱好者  阅读(315)  评论(0编辑  收藏  举报