欢迎关注公众号:“Cocos Creator 源码讲解”,一起学习。
/* Scales a Node object a zoom factor by modifying it's scale property.
* Relative to its changes.
* @class ScaleBy
* @extends ScaleTo
*/
/* 通过修改节点对象的缩放属性来缩放节点对象的缩放系数。
* 相对于它的变化。
* @class ScaleBy
* @extends ScaleTo
*/
cc.ScaleBy = cc.Class({
name: 'cc.ScaleBy',
/* 继承自cc.ScaleTo */
extends: cc.ScaleTo,
/* 设置target */
startWithTarget: function (target) {
cc.ScaleTo.prototype.startWithTarget.call(this, target);
/* end是当前的多少倍,减去当前。 */
this._deltaX = this._startScaleX * this._endScaleX - this._startScaleX;
this._deltaY = this._startScaleY * this._endScaleY - this._startScaleY;
},
/* 逆向action */
reverse: function () {
/* 产出一个新对象,设置最终的scalex,scaley,分别为原来scale的倒数 */
var action = new cc.ScaleBy(this._duration, 1 / this._endScaleX, 1 / this._endScaleY);
/* 复制当前属性给action */
this._cloneDecoration(action);
/* 把easelist里面的action 进行reverse */
this._reverseEaseList(action);
/* 返回action */
return action;
},
/* 复制Action
*/
clone: function () {
/* 创建一个对象 */
var action = new cc.ScaleBy();
/* 对对象进行属性设置 */
this._cloneDecoration(action);
/* 初始化参数,endscalex,endscaley */
action.initWithDuration(this._duration, this._endScaleX, this._endScaleY);
return action;
}
});
/**
* !#en
* Scales a Node object a zoom factor by modifying it's scale property.
* Relative to its changes.
* !#zh 按指定的倍数缩放节点大小。
* @method scaleBy
* @param {Number} duration duration in seconds
* @param {Number} sx sx scale parameter in X
* @param {Number|Null} [sy=] sy scale parameter in Y, if Null equal to sx
* @return {ActionInterval}
* @example
* // example without sy, it scales by 2 both in X and Y
* var actionBy = cc.scaleBy(2, 2);
*
* //example with sy, it scales by 0.25 in X and 4.5 in Y
* var actionBy2 = cc.scaleBy(2, 0.25, 4.5);
*/
/* 创建scaleBy对象 */
cc.scaleBy = function (duration, sx, sy) {
return new cc.ScaleBy(duration, sx, sy);
};