`

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

阅读更多
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;




  • 大小: 17.5 KB
  • 大小: 18.6 KB
  • 大小: 17.9 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics