cocos creator demo

获取prefab和获取脚本

properties: {
    settingsPrefab: {
         default: null,
         type: cc.Prefab
    },
}
this.settingsPrefab = cc.instantiate(this.settingsPrefab);
this.settingsPrefab.parent = this.node;
this.settingsPrefabScript = this.settingsPrefab.getComponent('setting');

替换label,图片

properties: {
    nickname_label: cc.Label,
    headimage: cc.Sprite,
    gobal_count: cc.Label,
},

onLoad() {
    this.nickname_label.string = myglobal.playerData.nickName;
    this.gobal_count.string = ":" + myglobal.playerData.gobal_count;
    var str = myglobal.playerData.avatarUrl;
    var head_image_path = "UI/headimage/" + str;
    cc.loader.loadRes(head_image_path, (err, img) => {
        this.headimage.spriteFrame = new cc.SpriteFrame(img);
    });
},

播放音乐和停止音乐

properties: {
    bgAudio: {
        default: null,
        type: cc.AudioClip
    }
},

this.bgAudioMusic = cc.audioEngine.stop(this.bgAudioMusic); //停止播放音乐
this.bgAudioMusic = cc.audioEngine.play(this.bgAudio, true, 1); //播放音乐

隐藏子节点

var gamebeforeUI = this.node.getChildByName("gamebeforeUI");
if (gamebeforeUI) {
    gamebeforeUI.active = false;
}

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(cocos,creator)