欢迎关注公众号:“Cocos Creator 源码讲解”,一起学习。
/*
* Moves a Node object to the position x,y. x and y are absolute coordinates by modifying its position property. <br/>
* Several MoveTo actions can be concurrently called, and the resulting <br/>
* movement will be the sum of individual movements.
* @class MoveTo
* @extends MoveBy
* @param {Number} duration duration in seconds
* @param {Vec2|Number} position
* @param {Number} [y]
* @example
* var actionBy = new cc.MoveTo(2, cc.v2(80, 80));
*/
/*
* 将 Node 对象移动到位置 x,y。通过修改其position属性,x和y为绝对坐标。 <br/>
* 可以同时调用多个 MoveTo 操作,结果<br/>
* 运动将是个体运动的总和。
* @类移动到
* @extends MoveBy
* @param {Number} 持续时间 持续时间(以秒为单位)
* @param {Vec2|Number} 位置
* @param {数字} [y]
* @例子
* var actionBy = new cc.MoveTo(2, cc.v2(80, 80));
*/
cc.MoveTo = cc.Class({
name: 'cc.MoveTo',
extends: cc.MoveBy,
ctor: function (duration, position, y) {
this._endPosition = cc.v2(0, 0);
position !== undefined && this.initWithDuration(duration, position, y);
},
/*
* Initializes the action.
* @param {Number} duration duration in seconds
* @param {Vec2} position
* @param {Number} [y]
* @return {Boolean}
*/
/* /*
* 初始化操作。
* @param {Number} 持续时间 持续时间(以秒为单位)
* @param {Vec2} 位置
* @param {数字} [y]
* @return {布尔值}
*/ */
initWithDuration: function (duration, position, y) {
if (cc.MoveBy.prototype.initWithDuration.call(this, duration, position, y)) {
/* 根据参数个数,进行重新定义第二个和第三个参数 */
if (position.x !== undefined) {
y = position.y;
position = position.x;
}
this._endPosition.x = position;
this._endPosition.y = y;
return true;
}
return false;
},
/* 复制Action */
clone: function () {
var action = new cc.MoveTo();
this._cloneDecoration(action);
action.initWithDuration(this._duration, this._endPosition);
return action;
},
/* target 赋值 */
startWithTarget: function (target) {
cc.MoveBy.prototype.startWithTarget.call(this, target);
this._positionDelta.x = this._endPosition.x - target.x;
this._positionDelta.y = this._endPosition.y - target.y;
}
});
/**
* !#en
* Moves a Node object to the position x,y. x and y are absolute coordinates by modifying its position property. <br/>
* Several MoveTo actions can be concurrently called, and the resulting <br/>
* movement will be the sum of individual movements.
* !#zh 移动到目标位置。
* @method moveTo
* @param {Number} duration duration in seconds
* @param {Vec2|Number} position
* @param {Number} [y]
* @return {ActionInterval}
* @example
* // example
* var actionBy = cc.moveTo(2, cc.v2(80, 80));
*/
/* 创建一个 moveTo对象 */
cc.moveTo = function (duration, position, y) {
return new cc.MoveTo(duration, position, y);
};