cocoscreator动态修改数据教程

cocoscreator动态修改数据教程


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;        

    },
});

先添加个了

 label: {
            default: null,
            type: cc.Label
        },

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

cocoscreator 播放动画

 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;
    },
});

原创文章如转载,请注明本文链接: http://newmiracle.cn/?p=3233

发表评论

电子邮件地址不会被公开。 必填项已用*标注