ActionScript - 屏幕包装渐变线?

问题描述 投票:0回答:2

我有一条直的渐变线,从屏幕的一端延伸到另一端。

屏幕包装此线条图的最佳(或唯一)方法是什么,以便它看起来像是在移动?

我目前的“解决方案”是以屏幕宽度的两倍绘制水平线,并复制每一半线的渐变图案。该线是中心注册的,它向右移动。一旦线的一半穿过舞台,线就会重置为它的起点。

有没有更好的办法?

actionscript-3 animation screen word-wrap
2个回答
1
投票

好吧,我能想到的唯一选择是使用绘图API绘制渐变笔划,计算每帧中的偏移量。但它肯定比仅仅在显示对象上应用位置变换更昂贵。仅有一点算术就足以让它变慢。

您提出的解决方案可能看起来不太优雅或高效但是因为我们在VM中运行高度优化以绘制和转换被遮挡的向量和位图(并且在其他所有优化中真的不可靠)我认为最好的选择就是信任VM在此刻。 :)


2
投票

你可以像这样绘制和设置渐变线的动画:

package  
{
import flash.display.GradientType;
import flash.display.InterpolationMethod;
import flash.display.SpreadMethod;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Matrix;

public class GradientLine extends Sprite 
{
    private var position:Number = 0;

    public function GradientLine() 
    {
        addEventListener( Event.ENTER_FRAME, drawLine );
    }

    private function drawLine(e:Event):void 
    {
        graphics.clear();

        var m:Matrix = new Matrix();
        m.createGradientBox( stage.stageWidth, stage.stageHeight, 0, position, 0 );

        position -= 10;//move from right to left by 10px

        graphics.lineStyle( 2 );
        graphics.lineGradientStyle( GradientType.LINEAR, [ 0xFF0000, 0xFFCC00, 0x0000CC ], [ 1, 1, 1 ], [ 0, 128, 255 ], m, SpreadMethod.REFLECT, InterpolationMethod.RGB, position );

        graphics.moveTo( 0, 250 );
        graphics.lineTo( stage.stageWidth, 250 );
    }
}
}

舞台需要可用。您可以将createGradientBox(宽度,高度)设置为您需要的大小。 SpreadMethod.REFLECT导致渐变反映,您可能想尝试SpreadMethod.REPEAT。

© www.soinside.com 2019 - 2024. All rights reserved.