const GameModule = require('../utils/GameModule'); cc.Class({ extends: cc.Component, properties: { bgmSpriteFrameArray: [cc.SpriteFrame], effectSpriteFrameArray: [cc.SpriteFrame], bgmButton: cc.Button, effectButton: cc.Button }, // LIFE-CYCLE CALLBACKS: onLoad () { let self = this; //改变背景音乐开启、关闭 this.changeBgmState = _.throttle(() => { GameModule.audioMng.playClickButton(); if (GameModule.audioMng.bgmOpen) { GameModule.audioMng.bgmOpen = false; self.bgmButton.getComponent(cc.Sprite).spriteFrame = this.bgmSpriteFrameArray[1]; } else { GameModule.audioMng.bgmOpen = true; self.bgmButton.getComponent(cc.Sprite).spriteFrame = this.bgmSpriteFrameArray[0]; } }, 500, true); //改变音效开启、关闭 this.changeEffectState = _.throttle(() => { if (GameModule.audioMng.soundEffectOpen) { GameModule.audioMng.playClickButton(); GameModule.audioMng.soundEffectOpen = false; self.effectButton.getComponent(cc.Sprite).spriteFrame = this.effectSpriteFrameArray[1]; } else { GameModule.audioMng.soundEffectOpen = true; self.effectButton.getComponent(cc.Sprite).spriteFrame = this.effectSpriteFrameArray[0]; } }, 500, true); if (GameModule.audioMng.bgmOpen) { this.bgmButton.getComponent(cc.Sprite).spriteFrame = this.bgmSpriteFrameArray[0]; } else { this.bgmButton.getComponent(cc.Sprite).spriteFrame = this.bgmSpriteFrameArray[1]; } if (GameModule.audioMng.soundEffectOpen) { this.effectButton.getComponent(cc.Sprite).spriteFrame = this.effectSpriteFrameArray[0]; } else { this.effectButton.getComponent(cc.Sprite).spriteFrame = this.effectSpriteFrameArray[1]; } }, start () { }, closeNode() { GameModule.audioMng.playClickButton(); this.node.destroy(); }, handleChangeBgmState() { this.changeBgmState(); }, //改变音效开启、关闭 handleChangeEffectState() { this.changeEffectState(); }, // update (dt) {}, });