大家好,我第一次尝试在 actionscript 3 中绘制多色渐变。
所以我从帮助文档中得到了这段代码,但我似乎无法获得垂直渐变,无论我使用什么公式或数字进行旋转,它都停留在默认的水平渐变上:(
我的代码:
您可以在跟踪中看到我尝试过的旋转代码...
package
{
import flash.display.DisplayObject;
import flash.display.GradientType;
import flash.display.SpreadMethod;
import flash.display.MovieClip;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.display.Shape;
import flash.geom.Matrix;
import flash.events.*;
public class MyGradient extends MovieClip
{
private var colorHolder:MovieClip = new MovieClip();
private var colorGrad:MovieClip = new MovieClip();
private var fillType:String = GradientType.LINEAR;
private var colors:Array = [0xFF0000, 0x4F8EEC];
private var alphas:Array = [1, 1];
private var ratios:Array = [0x00, 0xFF];
private var matr:Matrix = new Matrix();
private var spreadMethod:String = SpreadMethod.PAD;
public function MyGradient():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init():void
{
colorHolder = new MovieClip();
colorGrad = new MovieClip();
//matr.rotate(30*Math.PI/180);
//matr.rotate(45);
//matr.rotate(90);
//matr.rotate(Math.PI/90);
matr.rotate(Math.PI/9);
matr.createGradientBox(200, 200, 0, 0, 1);
colorGrad.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);
colorGrad.graphics.drawRect(0,0,200,200);
colorHolder.addChild(colorGrad);
addChild(colorHolder);
}
}
}
大量参与的更新修复:
matr.createGradientBox(200, 200, Math.PI/2, 0, 0);