/* Tints a Node that implements the cc.NodeRGB protocol from current tint to a custom one.
* Relative to their own color change.
* @class TintBy
* @extends ActionInterval
* @param {Number} duration duration in seconds
* @param {Number} deltaRed
* @param {Number} deltaGreen
* @param {Number} deltaBlue
* @example
* var action = new cc.TintBy(2, -127, -255, -127);
*/
/* 将实现 cc.NodeRGB 协议的节点从当前色调设置为自定义色调。
* 相对于自身的颜色变化。
* @类TintBy
* @extends ActionInterval
* @param {Number} 持续时间 持续时间(以秒为单位)
* @param {Number} deltaRed
* @param {Number} deltaGreen
* @param {Number} deltaBlue
* @例子
* var action = new cc.TintBy(2, -127, -255, -127);
*/
cc.TintBy = cc.Class({
name: 'cc.TintBy',
/* 继承自cc.ActionInterval */
extends: cc.ActionInterval,
/* 构造函数 到最终结果,当前的位移 参数对应是多少*/
ctor: function (duration, deltaRed, deltaGreen, deltaBlue) {
/* 初始化参数,间隔的by的rgb都是0 ,开始的rgb 都是0 */
this._deltaR = 0;
this._deltaG = 0;
this._deltaB = 0;
this._fromR = 0;
this._fromG = 0;
this._fromB = 0;
/* 调用父类方法 传递参数 实现参数赋值*/
deltaBlue !== undefined && this.initWithDuration(duration, deltaRed, deltaGreen, deltaBlue);
},
/*
* Initializes the action.
* @param {Number} duration
* @param {Number} deltaRed 0-255
* @param {Number} deltaGreen 0-255
* @param {Number} deltaBlue 0-255
* @return {Boolean}
*/
/*
* 初始化操作。
* @param {Number} 持续时间
* @param {Number} deltaRed 0-255
* @param {Number} deltaGreen 0-255
* @param {Number} deltaBlue 0-255
* @return {布尔值}
*/
initWithDuration: function (duration, deltaRed, deltaGreen, deltaBlue) {
/* /* 调用父类方法 传递参数 实现参数赋值*/ * /
if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
/* 各个通道的数值 */
this._deltaR = deltaRed;
this._deltaG = deltaGreen;
this._deltaB = deltaBlue;
return true;
}
return false;
},
/* 复制本action */
clone: function () {
/* new 一个action */
var action = new cc.TintBy();
/* 对action进行赋值 */
this._cloneDecoration(action);
/* 初始化时间和delta 间隔 参数 */
action.initWithDuration(this._duration, this._deltaR, this._deltaG, this._deltaB);
/* 返回当前new的action */
return action;
},
/* 传参target */
startWithTarget: function (target) {
cc.ActionInterval.prototype.startWithTarget.call(this, target);
/* 设置开始时候的参数 */
var color = target.color;
/* 起始color的 rgb数值进行初始化 */
this._fromR = color.r;
this._fromG = color.g;
this._fromB = color.b;
},
/* 每一帧更新 */
update: function (dt) {
/* 计算easetime */
dt = this._computeEaseTime(dt);
/* 根据时间,进行变化,当前的rgb参数分别为多少 */
this.target.color = cc.color(this._fromR + this._deltaR * dt,
this._fromG + this._deltaG * dt,
this._fromB + this._deltaB * dt);
},
/* 翻转action */
reverse: function () {
/* new 一个action,当前的rgb,减去这个数值 */
var action = new cc.TintBy(this._duration, -this._deltaR, -this._deltaG, -this._deltaB);
/* 对action进行赋值 */
this._cloneDecoration(action);
/* 把easelist里面的action 进行reverse */
this._reverseEaseList(action);
/* 返回new的这个actino */
return action;
}
});
/**
* !#en
* Tints a Node that implements the cc.NodeRGB protocol from current tint to a custom one.
* Relative to their own color change.
* !#zh 按照指定的增量修改颜色。
* @method tintBy
* @param {Number} duration duration in seconds
* @param {Number} deltaRed
* @param {Number} deltaGreen
* @param {Number} deltaBlue
* @return {ActionInterval}
* @example
* // example
* var action = cc.tintBy(2, -127, -255, -127);
*/
/* 创建tintBy对象 */
cc.tintBy = function (duration, deltaRed, deltaGreen, deltaBlue) {
return new cc.TintBy(duration, deltaRed, deltaGreen, deltaBlue);
};
CocosCreator 源码cc.TintBy详解
最新推荐文章于 2024-07-17 20:16:35 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)