【问题标题】:Countdown animation with EaselJsEaselJs 的倒计时动画
【发布时间】:2014-02-20 10:52:41
【问题描述】:

我正在尝试使用easeljs 模拟倒计时动画。我有一个它应该是什么样子的例子。 http://jsfiddle.net/eguneys/AeK28/

但它看起来像一个黑客,有没有合适/更好/灵活的方法来做到这一点?

换句话说,我如何定义一条路径,并用easeljs绘制该路径。

这看起来很难看:

     createjs.Tween.get(bar, {override: true}).to({x: 400}, 1500, createjs.linear)
.call(function() {
    createjs.Tween.get(bar, {override: true}).to({y: 400}, 1500, createjs.linear)
 .call(function() {
    createjs.Tween.get(bar, {override: true}).to({ x: 10 }, 1500, createjs.linear)
  .call(function() {
    createjs.Tween.get(bar, {override: true}).to({ y: 10 }, 1500, createjs.linear);
        })
    });
});

【问题讨论】:

  • 您是在尝试创建进度条还是类似于 Fiddle 的东西?
  • 类似于带有自定义路径的进度条。

标签: javascript animation path easeljs jstween


【解决方案1】:

您可以使用TweenJS MotionGuidePlugin 沿路径进行补间,而不是使用多个补间。

createjs.MotionGuidePlugin.install();
createjs.Tween.get(bar).to({
    guide: {path: [10,10, 10,10,400,10, 400,10,400,400, 400,400,10,400, 10,400,10,10]}
}, 6000, createjs.linear);

路径数组基本上是 moveTo 调用后跟多个 curveTo 调用的坐标集。坐标将沿这些调用产生的路径进行插值。


一种更模块化的方式来指定路径数组是让一个函数使用您声明的一组点来生成它。

function getMotionPathFromPoints (points) {
    var i, motionPath;

    for (i = 0, motionPath = []; i < points.length; ++i) {
        if (i === 0) {
            motionPath.push(points[i].x, points[i].y);
        } else {
            motionPath.push(points[i - 1].x, points[i - 1].y, points[i].x, points[i].y);
        }
    }

    return motionPath;
}

var points = [
    new createjs.Point(10, 10),
    new createjs.Point(400, 10),
    new createjs.Point(400, 400),
    new createjs.Point(10, 400),
    new createjs.Point(10, 10)
];

createjs.MotionGuidePlugin.install();
createjs.Tween.get(bar).to({
    guide: {path: getMotionPathFromPoints(points)}
}, 6000, createjs.linear);

FIDDLE

【讨论】:

  • 有没有办法让你的路径在它已经击中的点上保持可见?例如进度条