cocoscreator动态修改数据教程

cocoscreator动态修改数据教程
<pre>

cc.Class({
extends: cc.Component,

properties: {
label: {
default: null,
type: cc.Label
},
label1: {
default: null,
type: cc.Label
},
// defaults, set visually when attaching this script to the Canvas
text: 'Hello, Wordd'
},

// use this for initialization
onLoad: function () {
this.label.string = this.text;
this.label1.string = this.text;

},

// called every frame
update: function (dt) {
this.label.string = "fwe";
this.label1.string = this.text;

},
});
</pre>


先添加个了 <pre>
label: {
default: null,
type: cc.Label
},
</pre>


然后返回到UI界面 新建个label节点 然后拖进去 就好了 然后就可以 this.label.string = "fwe";控制了

 

cocoscreator 播放动画

<pre>
cc.Class({
extends: cc.Component,
properties: {
label: {
default: null,
type: cc.Label
},
label1: {
default: null,
type: cc.Label
},
anim: {
type: cc.Animation,
default: null,
},
// defaults, set visually when attaching this script to the Canvas
text: 'Hello, Wordd'
},
// use this for initialization
onLoad: function() {
this.label.string = this.text;
this.label1.string = this.text;
},
start: function() {
// this.anim_com.play("anim_class");
this.anim.play(); // 播放的是defalut clip指向的动画clip
},
// called every frame
update: function(dt) {
this.label.string = "fwe";
this.label1.string = this.text;
},
});
</pre>

posted @ 2019-11-12 15:38  newmiracle宇宙  阅读(1369)  评论(0编辑  收藏  举报