123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- //通用设置界面
- 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));
- }
- ZYGameTool.getInstance().OpenAd("banner", "banner");
- },
- 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) {},
- });
|