【问题标题】:easeljs animate forward and reverse within the canvaseaseljs 在画布内向前和向后设置动画
【发布时间】:2016-01-19 11:20:37
【问题描述】:

需要一些关于画架精灵动画的建议,来自demo they provided

我如何从代码事件中对画布中正在跑步的人进行正向和反向操作?

【问题讨论】:

    标签: javascript easeljs


    【解决方案1】:

    移动只是增加 x 位置。

    // New position is the current position, plus 150 pixels
    var position = grant.x + 150 * deltaS;
    // The delta is just a multiplier to keep the movement independent of the framerate.
    
    // Then "Grant" is set to the new position, unless the position is past
    // the right side of the canvas, in which case it is set to the left side again
    // (to wrap)
    grant.x = (position >= w + grantW) ? -grantW : position;
    

    要反转动画,您可以反转数学

    var position = grant.x - 150 * deltaS; // Move backwards
    grant.x = (position < 0) ? w : position; // Put on far right
    

    然后你可以水平翻转精灵让他走另一条路。

    grant.scaleX = -1;
    

    您可以对其他所有内容采取相同的方法。请注意,在演示中,精灵并没有真正相对于地面、背景等移动,它只是设置为视差效果。如果您想让某些东西更具交互性,您可能需要采用不同的方法。

    【讨论】:

    • 谢谢兰尼,反向工作,但我似乎无法让它在到达一端后转回。
    • 演示只是包装了位置。您需要更改它以检查边界,并改为更改它的行为。例如:if (grant.x &lt; 0) { moveRightAction(); } else if (grant.x &gt; w) { moveLeftAction(); }
    猜你喜欢
    • 2016-01-30
    • 2014-01-11
    • 1970-01-01
    • 2016-10-01
    • 2016-12-24
    • 1970-01-01
    • 2018-01-17
    • 1970-01-01
    • 2021-11-11
    相关资源
    最近更新 更多