【问题标题】:ActionScript - Screen Wrapping A Gradient Line?ActionScript - 屏幕环绕渐变线?
【发布时间】:2019-04-19 20:48:06
【问题描述】:

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

什么是最好的(或唯一的)屏幕环绕此线条图形的方法,使其看起来在移动?

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

有没有更好的办法?

【问题讨论】:

    标签: actionscript-3 animation screen word-wrap


    【解决方案1】:

    您可以像这样绘制渐变线并为其设置动画:

    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 ( width , height ) 设置为您需要的大小。 SpreadMethod.REFLECT 会导致渐变反射,您不妨试试 SpreadMethod.REPEAT。

    【讨论】:

    • +1 这当然有效,谢谢。不幸的是,正如 erkmene 指出的那样,它真的很贵。只是在台词动画时在舞台上移动我的鼠标就足以产生轻微的延迟。
    【解决方案2】:

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

    您提出的解决方案可能看起来不太优雅或高效,但因为我们在一个高度优化的 VM 中运行,以绘制和转换被遮挡的矢量和位图(而且确实不可靠关于其他所有优化)我认为最好的选择是此时只信任虚拟机。 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-31
      • 2017-01-26
      • 2017-10-22
      • 1970-01-01
      • 2010-11-06
      • 1970-01-01
      • 2019-12-24
      相关资源
      最近更新 更多