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>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM