zoukankan      html  css  js  c++  java
  • [ActionScript] AS3代码实现渐变遮罩效果

     1 import flash.display.Shape;
     2 import flash.display.GradientType;
     3 import flash.geom.Matrix;
     4 import flash.display.Sprite;
     5 
     6 var myShape:Shape = new Shape();
     7 var gradientBoxMatrix:Matrix = new Matrix();
     8 gradientBoxMatrix.createGradientBox(400, 400,0, 0, 0);//Math.PI*0.5是设置渐变转动90度为垂直(默认为水平,也可设任意角度)
     9 //参数填充类型,颜色数组,alpha数组,渐变比率
    10 myShape.graphics.beginGradientFill(GradientType.LINEAR, [0,0,0,0], [0,1,1,0], [1,1,1,255], gradientBoxMatrix);
    11 myShape.graphics.drawRect(0, 0, 400, 400);
    12 myShape.graphics.endFill();
    13 addChild(myShape);
    14 //然后就是把此对象设为遮罩层即可
    15 var spt:Sprite=new Sprite();
    16 spt.graphics.beginFill(0xFFCCCC);
    17 spt.graphics.drawRect(0, 0, 400, 400);
    18 spt.graphics.endFill();
    19 addChild(spt);
    20 //设为遮罩层
    21 spt.mask=myShape; 
    22 //这时还没完成,如果这样是看不到效果的,必须得再设置这两个对象的cacheAsBitmap属性为true,才可以,即
    23 myShape.cacheAsBitmap=true;
    24 spt.cacheAsBitmap=true;
    25 //设为遮罩层
    26 spt.mask=myShape; 
  • 相关阅读:
    UVALive 7509 Dome and Steles
    HDU 5884 Sort
    Gym 101194H Great Cells
    HDU 5451 Best Solver
    HDU 5883 The Best Path
    HDU 5875 Function
    卡特兰数
    UVa 11729 Commando War 突击战
    UVa 11292 The Dragon of Loowater 勇者斗恶龙
    Spark Scala Flink版本对应关系
  • 原文地址:https://www.cnblogs.com/frost-yen/p/4781672.html
Copyright © 2011-2022 走看看