自定义 Action 警告 cc.Class will automatically call super constructor of xxx, you should not call it manually.

  • 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 () {
    }
});

同问,这个用法文档里面也有介绍的,我这边是仅在编辑器里面出现这个警告。感觉怪怪的,按照文档的说法,继承类应该可以定义ctor呀, 这个警告是cc.warnId(3600)报出来的,在引擎文件CCClass.js里面
https://docs.cocos.com/creator/manual/zh/scripting/reference/class.html?h=super

@panda @jare

看了一下引擎代码,原来这个警告是用正则表达式来判定的,所以你的注释里面写了那个函数,也会给你警告。。。。,实际运行是没有任何问题的。。

看着烦不是。。。:sweat_smile: