SettingCtrl.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. const GameModule = require('../utils/GameModule');
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. bgmSpriteFrameArray: [cc.SpriteFrame],
  6. effectSpriteFrameArray: [cc.SpriteFrame],
  7. bgmButton: cc.Button,
  8. effectButton: cc.Button
  9. },
  10. // LIFE-CYCLE CALLBACKS:
  11. onLoad () {
  12. let self = this;
  13. //改变背景音乐开启、关闭
  14. this.changeBgmState = _.throttle(() => {
  15. GameModule.audioMng.playClickButton();
  16. if (GameModule.audioMng.bgmOpen) {
  17. GameModule.audioMng.bgmOpen = false;
  18. self.bgmButton.getComponent(cc.Sprite).spriteFrame = this.bgmSpriteFrameArray[1];
  19. } else {
  20. GameModule.audioMng.bgmOpen = true;
  21. self.bgmButton.getComponent(cc.Sprite).spriteFrame = this.bgmSpriteFrameArray[0];
  22. }
  23. }, 500, true);
  24. //改变音效开启、关闭
  25. this.changeEffectState = _.throttle(() => {
  26. if (GameModule.audioMng.soundEffectOpen) {
  27. GameModule.audioMng.playClickButton();
  28. GameModule.audioMng.soundEffectOpen = false;
  29. self.effectButton.getComponent(cc.Sprite).spriteFrame = this.effectSpriteFrameArray[1];
  30. } else {
  31. GameModule.audioMng.soundEffectOpen = true;
  32. self.effectButton.getComponent(cc.Sprite).spriteFrame = this.effectSpriteFrameArray[0];
  33. }
  34. }, 500, true);
  35. if (GameModule.audioMng.bgmOpen) {
  36. this.bgmButton.getComponent(cc.Sprite).spriteFrame = this.bgmSpriteFrameArray[0];
  37. } else {
  38. this.bgmButton.getComponent(cc.Sprite).spriteFrame = this.bgmSpriteFrameArray[1];
  39. }
  40. if (GameModule.audioMng.soundEffectOpen) {
  41. this.effectButton.getComponent(cc.Sprite).spriteFrame = this.effectSpriteFrameArray[0];
  42. } else {
  43. this.effectButton.getComponent(cc.Sprite).spriteFrame = this.effectSpriteFrameArray[1];
  44. }
  45. },
  46. start () {
  47. },
  48. closeNode() {
  49. GameModule.audioMng.playClickButton();
  50. this.node.destroy();
  51. },
  52. handleChangeBgmState() {
  53. this.changeBgmState();
  54. },
  55. //改变音效开启、关闭
  56. handleChangeEffectState() {
  57. this.changeEffectState();
  58. },
  59. // update (dt) {},
  60. });