WEB开发网
开发学院图形图像Flash Drawing arcs with AS3 阅读

Drawing arcs with AS3

 2009-10-18 00:00:00 来源:WEB开发网   
核心提示: you get this result:An arc from degree 14 to degree 180. It’s easy and simple and uses trigonometry (check this old tutorial if you think it&r

you get this result:

An arc from degree 14 to degree 180. It’s easy and simple and uses trigonometry (check this old tutorial if you think it’s a brain disease)

But the final application is a power meter like the one used in Pumpkin Story, and here it is, with a bit of the previous script and a bit of Flash artillery.

package {
 import flash.display.Sprite;
 import flash.events.MouseEvent;
 import flash.events.Event;
 public class arc extends Sprite {
  var my_canvas:Sprite = new Sprite();
  var deg_to_rad=0.0174532925;
  var charging:Boolean=false;
  var power:int=0;
  public function arc() {
   addChild(my_canvas);
   stage.addEventListener(MouseEvent.MOUSE_UP, shoot);
   stage.addEventListener(MouseEvent.MOUSE_DOWN,charge);
   addEventListener(Event.ENTER_FRAME, on_enter_frame);
  }
  public function draw_arc(movieclip,center_x,center_y,radius,angle_from,angle_to,precision) {
   var angle_diff=angle_to-angle_from;
   var steps=Math.round(angle_diff*precision);
   var angle=angle_from;
   var px=center_x+radius*Math.cos(angle*deg_to_rad);
   var py=center_y+radius*Math.sin(angle*deg_to_rad);
   movieclip.graphics.moveTo(px,py);
   for (var i:int=1; i<=steps; i++) {
    angle=angle_from+angle_diff/steps*i;
    movieclip.graphics.lineTo(center_x+radius*Math.cos(angle*deg_to_rad),center_y+radius*Math.sin(angle*deg_to_rad));
   }
  }
  public function charge(e:MouseEvent) {
   charging=true;
  }
  public function shoot(e:MouseEvent) {
   charging=false;
   my_canvas.graphics.clear();
   power=0;
  }
  public function on_enter_frame(e:Event) {
   if (charging) {
    power++;
    if (power>=120) {
     power-=120;
    }
    my_canvas.graphics.clear();
    my_canvas.graphics.lineStyle(20,0x000000,1);
    draw_arc(my_canvas,250,200,150,270,270+power*3,1);
   }
  }
 }
}

And this is the result:

Press and hold the mouse to charge the power, release to reset.

上一页  1 2 

Tags:Drawing arcs with

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接