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