-
Notifications
You must be signed in to change notification settings - Fork 119
ui_path_zh
yinlijun2004 edited this page Dec 25, 2015
·
12 revisions
UIPath 控制物体按照指定的路径运动。目前路径支持直线,抛物线,二次和三次贝塞尔曲线,sin/cos函数和圆弧曲线。可以指定运动的速度(由duration控制)和加速度(由interpolator决定)。
使用时先放一个UIPath对象到场景中,然后在onInit事件里增加路径,在任何时间都可以向UIPath增加对象或删除对象。
它是UIElement的子类。
注意:
- 1.文档中时长的单位为毫秒,速度单位为像素/秒,加速单位为像素/秒^2,角度单位为幅度。
- 2.插值算法实现加速/加速/匀速等效果,请参考插值算法。
- addLine(duration, interpolator, p1, p2) 增加一条直线到路径中。
- duration 经过此路径需要的时间。
- interpolator 插值算法。
- p1 起点。
- p2 终点。
- addArc(duration, interpolator, origin, r, sAngle, eAngle) 增加一条弧线到路径中。
- duration 经过此路径需要的时间。
- interpolator 插值算法。
- origin 圆心。
- r 半径。
- sAngle 初始角度。
- eAngle 结束角度。
- addPara(duration, interpolator, p, a, v) 增加一条抛物线到路径中。
- duration 经过此路径需要的时间,单位为毫秒。
- interpolator 插值算法。
- p 初始位置。
- a X/Y方向上的加速度。
- v X/Y方向上的初速度。
- addSin(duration, interpolator, p, waveLenth, v, amplitude, phaseOffset) 增加一条sin/cos曲线到路径中。
- duration 经过此路径需要的时间,单位为毫秒。
- interpolator 插值算法。
- p 初始位置。
- waveLenth 波长。
- v 波速(X方向上的速度)。
- amplitude 振幅。
- phaseOffset 角度偏移。
- addBezier(duration, interpolator, p1, p2, p3, p4) 增加一条三次贝塞尔曲线到路径中。
- duration 经过此路径需要的时间,单位为毫秒。
- interpolator 插值算法。
- p1 起点。
- p2 控制点1。
- p3 控制点2。
- p4 终点。
- addQuad(duration, interpolator, p1, p2, p3) 增加一条二次贝塞尔曲线到路径中。
- duration 经过此路径需要的时间,单位为毫秒。
- interpolator 插值算法。
- p1 起点。
- p2 控制点。
- p3 终点。
-
getDuration() 获取路径的需要的总时间。
-
getEndPoint() 获取路径的的终点(可以用作后续路径的起点)。
-
getPosition(elapsedTime) 获取指定时刻对应路径上的位置。
- elapsedTime 时刻。
- getDirection(elapsedTime) 获取指定时刻对应路径上的方向(0-2PI)。
- elapsedTime 时刻。
-
resetPath() 重置路径。
-
addObj(shape, onStep, onDone, delayTime, noRotation) 增加一个对象,让它沿路径运动。
- shape 对象。
- onStep 每一步的回调函数(可选)。
- onDone 完成时的回调函数(可选)。
- delayTime 延迟启动时间(可选)。
- noRotation 是否禁止旋转(可选)。
- removeObj(shape) 从路径中移除一个对象。
- shape 对象。
-
restart() 重新开始。
-
pause() 暂停运动。
-
resume() 恢复运动。
###示例:
var win = this.getWindow();
var interpolator = null;
//1.Add Path First
this.addPara(1500, interpolator, {x:0, y:0}, {x:0, y:600}, {x:300, y:0});
this.addArc(2000, interpolator, {x:win.w>>1, y:win.h>>1}, 200, 0, Math.PI * 2);
this.addLine(1000, interpolator, {x:0, y:0}, {x:win.w, y:win.h});
this.addSin(4000, interpolator, {x:0, y:300}, 240, 120, 120, 0);
this.addBezier(1000, interpolator, {x:0, y:600}, {x:100, y:600}, {x:400, y:500}, {x:480, y:10});
this.addQuad(1000, interpolator, {x:0, y:400}, {x:400, y:400}, {x:400, y:0});
//2.Add Obj that run along path.
this.addObj(win.find("tree"));
this.addObj(win.find("boy"), null, null, 2000, true);