- Creator 版本:2.0.8
给网上找了一段代码想改写一下,但是总是有警告
cc.Class will automatically call super constructor of cc.LabelCounter, you should not call it manually.
这个应该要怎么解决。。
下面是代码
cc.LabelCounter = cc.Class({
name: 'cc.LabelCounter',
extends: cc.ActionInterval,
ctor: function (duration, finalValue, initialValue = 0) {
// cc.ActionInterval.prototype.ctor.call(this);
this._LabelComponent = null;
this._beforeText = "";
this._afterText = "";
this._finalValue = 0;
this._initialValue = 0;
this.step_ = 0;
this.asProgress_ = false;
this.maxValue_ = 0;
finalValue !== undefined && cc.LabelCounter.prototype.initWithDuration.call(this,duration, finalValue, initialValue);
},
initWithDuration: function(duration,finalValue,initialValue = 0){
if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
this._finalValue = finalValue;
this._initialValue = initialValue;
return true;
}
return false;
},
clone:function () {
var action = new cc.LabelCounter();
this._cloneDecoration(action);
action.initWithDuration(this._duration, this._finalValue, this._initialValue);
return action;
},
startWithTarget:function (target) {
cc.ActionInterval.prototype.startWithTarget.call(this, target);
this.step_ = this._finalValue - this._initialValue;
this._LabelComponent = target.getComponent(cc.Label);
if(this._LabelComponent === null){
this._LabelComponent = target.getComponent(cc.RichText);
}
this.setValue(this._initialValue);
},
update:function (dt) {
dt = this._computeEaseTime(dt);
let _visualValue = this._initialValue + this.step_ * dt;
_visualValue = Math.ceil(_visualValue);
this.setValue(_visualValue);
},
setValue:function(value){
this._LabelComponent.string = cc.js.formatStr("%s%s%s",this._beforeText,value,this._afterText);
},
reverse:function () {
}
});