Label是app中经常要用到的组件,那么有哪些实现方法呢?
第一种:UI编辑器界面绑定
先定义属性
myLabel:{
type: cc.Label,
default: null,
},
然后加载脚本,并进行绑定

改变文本内容:
this.myLabel.string = "hahahaha";
第二种,通过代码获取
console.log("this.name:", this.name);
console.log("this.node.name:", this.node.name);
var _node = this.node.getChildByName("myLabel");
console.log("_node:", _node);
var _label = _node.getComponent(cc.Label);
console.log("_label:", _label);
_label.string = "abc";
this和this.node是脚本挂载的节点,我这里是bg


本文介绍了在Creator中实现Label文本组件的两种方法:通过UI编辑器界面绑定和代码获取。还深入探讨了RichText的属性,支持的标签如颜色、图片插入、下划线、斜体和粗体等,并讲解了预制体的使用,帮助开发者更好地理解和应用Label组件。

5022

被折叠的 条评论
为什么被折叠?



