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>
如果遇到什么不懂的地方直接关注公众号留言(本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。)
作者:newmiracle
出处:https://www.cnblogs.com/newmiracle/