【发布时间】:2016-01-19 11:20:37
【问题描述】:
需要一些关于画架精灵动画的建议,来自demo they provided
我如何从代码事件中对画布中正在跑步的人进行正向和反向操作?
【问题讨论】:
标签: javascript easeljs
需要一些关于画架精灵动画的建议,来自demo they provided
我如何从代码事件中对画布中正在跑步的人进行正向和反向操作?
【问题讨论】:
标签: javascript easeljs
移动只是增加 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 < 0) { moveRightAction(); } else if (grant.x > w) { moveLeftAction(); }