欢迎关注公众号:“Cocos Creator 源码讲解”,一起学习。
/*
* Rotates a Node object clockwise a number of degrees by modifying its angle property.
* Relative to its properties to modify.
* @class RotateBy
* @extends ActionInterval
* @param {Number} duration duration in seconds
* @param {Number} deltaAngle deltaAngle in degrees
* @example
* var actionBy = new cc.RotateBy(2, 360);
*/
/* /*
* 通过修改 Node 对象的角度属性,将 Node 对象顺时针旋转一定角度。
* 相对于其属性进行修改。
* @类RotateBy
* @extends ActionInterval
* @param {Number} 持续时间 持续时间(以秒为单位)
* @param {Number} deltaAngle deltaAngle 以度为单位
* @例子
* var actionBy = new cc.RotateBy(2, 360);
*/ * /
cc.RotateBy = cc.Class({
name: 'cc.RotateBy',
extends: cc.ActionInterval,
statics: {
_reverse: false,
},
/* 构造函数 */
ctor: function (duration, deltaAngle) {
deltaAngle *= cc.RotateBy._reverse ? 1 : -1;
this._deltaAngle = 0;
this._startAngle = 0;
deltaAngle !== undefined && this.initWithDuration(duration, deltaAngle);
},
/*
* Initializes the action.
* @param {Number} duration duration in seconds
* @param {Number} deltaAngle deltaAngle in degrees
* @return {Boolean}
*/
/* /*
* 初始化操作。
* @param {Number} 持续时间 持续时间(以秒为单位)
* @param {Number} deltaAngle deltaAngle 以度为单位
* @return {布尔值}
*/ */
initWithDuration: function (duration, deltaAngle) {
if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
this._deltaAngle = deltaAngle;
return true;
}
return false;
},
/* 复制Acton ,cc.RotateBy */
clone: function () {
var action = new cc.RotateBy();
this._cloneDecoration(action);
action.initWithDuration(this._duration, this._deltaAngle);
return action;
},
/* 调用cc.ActionInterval 的startWithTarget 方法 */
startWithTarget: function (target) {
cc.ActionInterval.prototype.startWithTarget.call(this, target);
this._startAngle = target.angle;
},
update: function (dt) {
/* 时时更新 */
dt = this._computeEaseTime(dt);
if (this.target) {
/* 当前angle更新,开始的angle + 总计划rotate的angle *帧时间 */
this.target.angle = this._startAngle + this._deltaAngle * dt;
}
},
reverse: function () {
var action = new cc.RotateBy();
action.initWithDuration(this._duration, -this._deltaAngle);
this._cloneDecoration(action);
this._reverseEaseList(action);
return action;
}
});
/**
* !#en
* Rotates a Node object clockwise a number of degrees by modifying its angle property.
* Relative to its properties to modify.
* !#zh 旋转指定的角度。
* @method rotateBy
* @param {Number} duration duration in seconds
* @param {Number} deltaAngle deltaAngle in degrees
* @return {ActionInterval}
* @example
* // example
* var actionBy = cc.rotateBy(2, 360);
*/
/* 创建一个 rotateBy对象*/
cc.rotateBy = function (duration, deltaAngle) {
return new cc.RotateBy(duration, deltaAngle);
};