欢迎关注公众号:“Cocos Creator 源码讲解”,一起学习。
/* An action that moves the target with a cubic Bezier curve to a destination point.
* @class BezierTo
* @extends BezierBy
* @param {Number} t
* @param {Vec2[]} c - Array of points
* @example
* var bezier = [cc.v2(0, windowSize.height / 2), cc.v2(300, -windowSize.height / 2), cc.v2(300, 100)];
* var bezierTo = new cc.BezierTo(2, bezier);
*/
/* 使用三次贝塞尔曲线将目标移动到目标点的动作。
* @贝塞尔托类
* @extends BezierBy
* @param {数字} t
* @param {Vec2[]} c -点数组
* @例子
* var bezier = [cc.v2(0, windowSize.height /2), cc.v2(300, -windowSize.height /2), cc.v2(300, 100)];
* var bezierTo = new cc.BezierTo(2, 贝塞尔曲线);
*/
cc.BezierTo = cc.Class({
name: 'cc.BezierTo',
extends: cc.BezierBy,
ctor: function (t, c) {
this._toConfig = [];
c && this.initWithDuration(t, c);
},
/*
* Initializes the action.
* @param {Number} t time in seconds
* @param {Vec2[]} c - Array of points
* @return {Boolean}
*/
initWithDuration: function (t, c) {
if (cc.ActionInterval.prototype.initWithDuration.call(this, t)) {
this._toConfig = c;
return true;
}
return false;
},
/* 复制action */
clone: function () {
var action = new cc.BezierTo();
this._cloneDecoration(action);
action.initWithDuration(this._duration, this._toConfig);
return action;
},
/* 设置target */
startWithTarget: function (target) {
cc.BezierBy.prototype.startWithTarget.call(this, target);
var locStartPos = this._startPosition;
var locToConfig = this._toConfig;
var locConfig = this._config;
locConfig[0] = locToConfig[0].sub(locStartPos);
locConfig[1] = locToConfig[1].sub(locStartPos);
locConfig[2] = locToConfig[2].sub(locStartPos);
}
});
/**
* !#en An action that moves the target with a cubic Bezier curve to a destination point.
* !#zh 按贝赛尔曲线轨迹移动到目标位置。
* @method bezierTo
* @param {Number} t
* @param {Vec2[]} c - Array of points
* @return {ActionInterval}
* @example
* // example
* var bezier = [cc.v2(0, windowSize.height / 2), cc.v2(300, -windowSize.height / 2), cc.v2(300, 100)];
* var bezierTo = cc.bezierTo(2, bezier);
*/
cc.bezierTo = function (t, c) {
return new cc.BezierTo(t, c);
};