欢迎关注公众号:“Cocos Creator 源码讲解”,一起学习。
/*
* Moves a Node object to a parabolic position simulating a jump movement by modifying it's position property. <br />
* Jump to the specified location.
* @class JumpTo
* @extends JumpBy
* @param {Number} duration
* @param {Vec2|Number} position
* @param {Number} [y]
* @param {Number} [height]
* @param {Number} [jumps]
* @example
* var actionTo = new cc.JumpTo(2, cc.v2(300, 0), 50, 4);
* var actionTo = new cc.JumpTo(2, 300, 0, 50, 4);
*/
/*
* 通过修改 Node 对象的位置属性,将 Node 对象移动到模拟跳跃运动的抛物线位置。<br/>
* 跳转到指定位置。
* @类跳转
* @extends JumpBy
* @param {Number} 持续时间
* @param {Vec2|Number} 位置
* @param {数字} [y]
* @param {数字} [高度]
* @param {Number} [跳跃]
* @例子
* var actionTo = new cc.JumpTo(2, cc.v2(300, 0), 50, 4);
* var actionTo = new cc.JumpTo(2, 300, 0, 50, 4);
*/
cc.JumpTo = cc.Class({
name: 'cc.JumpTo',
extends: cc.JumpBy,
ctor: function (duration, position, y, height, jumps) {
this._endPosition = cc.v2(0, 0);
height !== undefined && this.initWithDuration(duration, position, y, height, jumps);
},
/*
* Initializes the action.
* @param {Number} duration
* @param {Vec2|Number} position
* @param {Number} [y]
* @param {Number} height
* @param {Number} jumps
* @return {Boolean}
* @example
* actionTo.initWithDuration(2, cc.v2(300, 0), 50, 4);
* actionTo.initWithDuration(2, 300, 0, 50, 4);
*/
/*
* 初始化操作。
* @param {Number} 持续时间
* @param {Vec2|Number} 位置
* @param {数字} [y]
* @param {Number} 高度
* @param {Number} 跳转
* @return {布尔值}
* @例子
* actionTo.initWithDuration(2, cc.v2(300, 0), 50, 4);
* actionTo.initWithDuration(2, 300, 0, 50, 4);
*/
initWithDuration: function (duration, position, y, height, jumps) {
if (cc.JumpBy.prototype.initWithDuration.call(this, duration, position, y, height, jumps)) {
if (jumps === undefined) {
y = position.y;
position = position.x;
}
this._endPosition.x = position;
this._endPosition.y = y;
return true;
}
return false;
},
/* 设置target */
startWithTarget: function (target) {
cc.JumpBy.prototype.startWithTarget.call(this, target);
this._delta.x = this._endPosition.x - this._startPosition.x;
this._delta.y = this._endPosition.y - this._startPosition.y;
},
/* 复制action */
clone: function () {
var action = new cc.JumpTo();
this._cloneDecoration(action);
action.initWithDuration(this._duration, this._endPosition, this._height, this._jumps);
return action;
}
});
/**
* !#en
* Moves a Node object to a parabolic position simulating a jump movement by modifying its position property. <br />
* Jump to the specified location.
* !#zh 用跳跃的方式移动到目标位置。
* @method jumpTo
* @param {Number} duration
* @param {Vec2|Number} position
* @param {Number} [y]
* @param {Number} [height]
* @param {Number} [jumps]
* @return {ActionInterval}
* @example
* // example
* var actionTo = cc.jumpTo(2, cc.v2(300, 300), 50, 4);
* var actionTo = cc.jumpTo(2, 300, 300, 50, 4);
*/
/* 创建一个jumpTo对象 */
cc.jumpTo = function (duration, position, y, height, jumps) {
return new cc.JumpTo(duration, position, y, height, jumps);
};