Egret 自定义皮肤—引入类中

创建egret游戏项目需要创建大量的皮肤EXML文件,创建之后在嵌入EXML到代码: (类似于JSON)

  • 第一种直接在代码中嵌入EXML文本内容
  • 直接把skinName设置为exml文件的路径。
class ExmlTestView extends eui.Component{
    public constructor() {
        super();
        this.addEventListener(eui.UIEvent.COMPLETE,this.onComplete,this);
        this.skinName = "xxxx(.exml)";
        this.touchChildren = true;
    }

    public label: eui.Label;

    private onComplete() {
        this.label.text = "hello world!";
        this.label.textColor = 0xff0000;
    }
    
    //createChildren():用来对未绑定皮肤的手动调用创建皮肤里的内容到界面
    //childrenCreated():创建完成后底层会调用这个函数,用来覆写作一些初始化处理的(是在组件初始化完成后回调)
    private createChildren() {
    
        super.createChildren();
    
    }
}

猜你喜欢

转载自www.cnblogs.com/mqflive81/p/11233632.html