//通用设置界面 var ZYGameTool = require('GameTool'); cc.Class({ extends: cc.Component, properties: { btn: { title: "按钮", type: cc.Node, default:[], }, soundSp: { title: "音效开关", type: cc.Node, default:[], }, musicSp: { title: "音乐开关", type: cc.Node, default:[], }, }, // LIFE-CYCLE CALLBACKS: onLoad () { this.node.on(cc.Node.EventType.TOUCH_START, this.touchBegin.bind(this), this); for (var i in this.btn){ this.btn[i].on('click', function (event) { this.clickCall(event); }.bind(this)); } }, start () { this.init(); }, /** * 初始化当前设置状态 */ init() { this.soundSp[0].active = playeSound == 1; this.soundSp[1].active = playeSound == 0; this.musicSp[0].active = playeMusic == 1; this.musicSp[1].active = playeMusic == 0; }, /** * 开关按钮 * @param event */ clickCall(event){ var name = event.node.name.toString(); if (name === "close"){ this.closeWindos(); return; } if (name === "soundBtn"){ this.soundCall(); } else if (name === "musicBtn"){ this.musckCall(); } this.saveData(); }, /** * 音效回调设置状态 */ soundCall: function(){ playeSound = playeSound === 1 ? 0 : 1; this.soundSp[0].active = playeSound == 1; this.soundSp[1].active = playeSound == 0; }, /** * 音乐回调设置状态 */ musckCall:function(){ playeMusic = playeMusic === 1 ? 0 : 1; this.musicSp[0].active = playeMusic == 1; this.musicSp[1].active = playeMusic == 0; zy.isStopBgMusic(); }, /** * 保存数据到本地 */ saveData: function(){ ZYGameTool.getInstance().setIntegerForKey(localDataItem.playeSound, playeSound);//音效开关 ZYGameTool.getInstance().setIntegerForKey(localDataItem.playeMusic, playeMusic);//背景音乐开关 }, /** * 点击任意地方关闭当前窗口 */ closeWindos:function () { this.node.destroy(); }, touchBegin: function () { this.node.destroy(); }, // update (dt) {}, });