ActionScript 3 创建一个褪色的圆形面具

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 创建一个褪色的圆形面具相关的知识,希望对你有一定的参考价值。

/*
Steve Ottenad - Nov 20, 2009 - AS3 Circle Drawing/ Clock Wipe Snippet

This Snippet works by drawing and then fading a succession of small triangles to make a circle/polygon.
It relies on TweenMax, a free tweening engine found at http://blog.greensock.com/tweenmax/.

Parameters:
centerX        (Number) - The X coordinate of the center of the circle to be drawn.
centerY        (Number) - The Y coordinate of the center of the circle to be drawn.
radius         (Number) - The desired radius of the circle.
increment      (Number) - The amount of degrees you want to add each time a wedge is drawn. If increment = 2, then 180 wedges will be drawn (360/2). If increment = 36, then 10 wedges will be drawn (360/10).
timeIncrement  (Number) - The amount of milliseconds between each wedge being drawn.
Container   (MovieClip) - The containing element.

Sample Usage: drawCircle(centerX, centerY , radius, increment , timeIncrement, container);
*/


function drawCircle(centerX:Number, centerY:Number, radius:Number, increment:Number, timeIncrement:Number, container:MovieClip){

//Define Variables
var radius:Number = radius;
var iniX:Number = centerX;
var iniY:Number = centerY;
var increment:Number = increment;
var totalDegrees:Number = 0;
var degInRad:Number;
var degInRad1:Number;
outline.visible = true;

//Create Timer
var maskTimer:Timer = new Timer(timeIncrement);
maskTimer.addEventListener(TimerEvent.TIMER, drawSegment);
maskTimer.start();

//Start Drawing
container.graphics.moveTo(iniX, iniY);
	function drawSegment(e:TimerEvent){
		if(totalDegrees < 362 && keepLoading){
			//Convert to Radians
			degInRad = totalDegrees * (Math.PI / 180);
			degInRad1 = Number(totalDegrees+increment) * (Math.PI / 180);
			//Find X,Y
			var x1:Number = radius * Math.cos( degInRad ) + iniX;
			var y1:Number = radius * Math.sin( degInRad ) + iniY;
			var x2:Number = radius * Math.cos( degInRad1 ) + iniX;
			var y2:Number = radius * Math.sin( degInRad1 ) + iniY;
	
			var wedge:Sprite = new Sprite();
			wedge.alpha = 0;
			
			//Define Color
			wedge.graphics.beginFill(0x000000);
			wedge.graphics.moveTo(iniX, iniY);
			wedge.graphics.lineTo(x1, y1);
			wedge.graphics.lineTo(x2, y2);
			wedge.graphics.lineTo(iniX, iniY);
			
			//Fade In (Time == 1 in this example
			TweenMax.to (wedge, 1, {alpha:1});
			container.addChild(wedge);
			
			totalDegrees+= increment
			;
		}else{
			maskTimer.stop();
		}
	}
}

以上是关于ActionScript 3 创建一个褪色的圆形面具的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 圆形文本字段

ActionScript 3 AS3圆形小数位

ActionScript 3 AS3圆形半径定位动画

ActionScript 3 AS3图像映射,圆形,斜角滤波器

ActionScript 3 带有圆形预加载器微调器的AS3 Image Loader

使用 CALayers 遮罩以在褪色的黑色视图中显示空心圆圈