ITeye博客

[转] 一种完全没有边缘痕迹的渐变AS做法

AS3 · 2011-10-23 00:21 · 文章转载 · 源码范例 · AS3收集 · Web前端 · Markdown

http://bbs.9ria.com/viewthread.php?tid=101161&extra=page%3D1%26amp%3Borderby%3Ddateline%26amp%3Bfilter%3D2592000


import flash.display.Sprite;
import flash.display.Shape;
import flash.display.GradientType;
import flash.geom.Matrix;

var sp:Sprite = new Sprite();
var sh:Shape = new Shape();
var w:Number = 255*2;
var mat:Matrix = new Matrix();
mat.createGradientBox(w,w,0,-w/2,-w/2);
sh.graphics.beginGradientFill(GradientType.RADIAL,[0,0],[1,0],[0,255],mat);
sh.graphics.drawCircle(0,0,w/2);
var sh2:Shape = new Shape();
sh2.graphics.beginGradientFill(GradientType.RADIAL,[0,0],[1,0],[0,255],mat);
sh2.graphics.drawCircle(0,0,w/2);
sp.addChild(sh2);
sp.addChild(sh);
sh.cacheAsBitmap = true;
sh2.cacheAsBitmap = true;
sh.mask = sh2;
this.addChild(sp);
sp.x = 300;
sp.y = 200;

其实就是用一个渐变给这个渐变做alpha mask,flash运算之后就是这个效果(我这里是用和原来一样的渐变)

当然调整一些值还能产生一些边缘平滑的其它效果,比如这个光晕。



import flash.display.Sprite;
import flash.display.Shape;
import flash.display.GradientType;
import flash.geom.Matrix;

var sp:Sprite = new Sprite();
var sh:Shape = new Shape();
var w:Number = 255*2;
var mat:Matrix = new Matrix();
mat.createGradientBox(w,w,0,-w/2,-w/2);
sh.graphics.beginGradientFill(GradientType.RADIAL,[0,0],[1,0],[0,255],mat);
sh.graphics.drawCircle(0,0,w/2);
var sh2:Shape = new Shape();
sh2.graphics.beginGradientFill(GradientType.RADIAL,[0,0],[1,0],[70,255],mat);
sh2.graphics.drawCircle(0,0,w/2);
sp.addChild(sh2);
sp.addChild(sh);
sh.cacheAsBitmap = true;
sh2.cacheAsBitmap = true;
sh.mask = sh2;
this.addChild(sp);
sp.x = 300;
sp.y = 200;


评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。