creator 2.1.4 动态 addComponent( cc.Label ) 报错

  • Creator 版本:2.1.4

  • 目标平台: 微信小游戏

  • 使用语言: TypeScript

  • 详细报错信息,包含调用堆栈:

  • 重现方式:
    let node = new cc.Node();
    node.addComponent( cc.Label );
    发布 微信小游戏

  • 之前哪个版本是正常的 :2.0.8 , 2.1.0

  • 出现概率:100%

  • 代码:

import Css from "./Utils/Css";

const { ccclass, property } = cc._decorator;

@ccclass
export default class Test extends cc.Component {

    @property( cc.Label )
    label: cc.Label = null;

    @property
    text: string = 'hello';

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    async start() {
        let node: cc.Node = await Css.Ui.getInt().createLabel( "11" );
        node.x = 100;
        node.y = 100;
        this.node.addChild( node);
    }

    // update (dt) {}
}


public async createLabel( str: string = "label", fontSize: number = 40, color: cc.Color = cc.color( 0XFFFFFF ), fontName?: string ) {
            let node: cc.Node = new cc.Node();
            let label = node.addComponent( cc.Label );

            console.log( "labekl", label );
            console.log( "cc.Label", cc.Label);

            label.string = str;
            label.fontSize = fontSize;
            label.lineHeight = fontSize;
            node.color = color;
            if ( fontName ) {
                await Css.Label.getInt().setFontEx( node, fontName );
            }
            return node;
        }

测试没有复现,麻烦给个完整的demo吧

找到问题了…是我之前在 2.0.8版本.定义了一套发布流… 自定义了一个 main.js 文件…和现在2.1.4版本的main有差别.