在greensock LinePath2D中淡出和淡出项目

时间:2016-01-04 20:14:57

标签: actionscript-3 greensock tweenmax

这是LinePath2D类

中提供的示例代码
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.motionPaths.*;
import flash.geom.Point;

//create a LinePath2D with 5 Points
var path:LinePath2D = new LinePath2D([new Point(0, 0), 
                                      new Point(100, 100), 
                                      new Point(350, 150),
                                      new Point(50, 200),
                                      new Point(550, 400)]);

//add it to the display list so we can see it (you can skip this if you prefer)
addChild(path);

//create an array containing 30 blue squares
var boxes:Array = [];
for (var i:int = 0; i < 30; i++) {
    boxes.push(createSquare(10, 0x0000FF));
}

//distribute the blue squares evenly across the entire path and set them to autoRotate
path.distribute(boxes, 0, 1, true);

//put a red square exactly halfway through the 2nd segment
path.addFollower(createSquare(10, 0xFF0000), path.getSegmentProgress(2, 0.5));

//tween all of the squares through the path once (wrapping when they reach the end)
TweenMax.to(path, 20, {progress:1});

//while the squares are animating through the path, tween the path's position and rotation too!
TweenMax.to(path, 3, {rotation:180, x:550, y:400, ease:Back.easeOut, delay:3});

//method for creating squares
function createSquare(size:Number, color:uint=0xFF0000):Shape {
    var s:Shape = new Shape();
    s.graphics.beginFill(color, 1);
    s.graphics.drawRect(-size / 2, -size / 2, size, size);
    s.graphics.endFill();
    this.addChild(s);
    return s;
}

将元素淡入淡出的最简单方法是什么?

我应该为每个项添加补间,还是应该挂钩更新监听器?

1 个答案:

答案 0 :(得分:0)

我使用了这个

        TweenMax.to(path, $speedNorm, { progress:1, ease:Linear.easeNone, repeat: -1, onUpdate:function():void
            {
                for (var j:int = 0; j < path.followers.length; j++) 
                {
                    var $follower:PathFollower = path.followers[j];
                    if ($follower.progress < 1/$numPoints) {
                        $follower.target.alpha = $follower.progress * $numPoints;
                    }
                    else if ($follower.progress > 1-1/$numPoints) {
                        $follower.target.alpha = (1-$follower.progress) * $numPoints;
                    }
                }
            }
        });

根据示例

,$ numpoints为30