CRASHAudioManager.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. let Global = require("Global");
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. sfxToggle: cc.Toggle,
  6. bgmToggle: cc.Toggle,
  7. shakeToggle: cc.Toggle,
  8. },
  9. onLoad() {
  10. this.isPlayBGM = false;
  11. this.bgmVolume = parseFloat(Global.getLocalStorageVaule("bgmVolume", 0.5));//.toFixed(1);
  12. this.sfxVolume = parseFloat(Global.getLocalStorageVaule("sfxVolume", 0.5));//.toFixed(1);
  13. this.shakeOpen = parseFloat(Global.getLocalStorageVaule("shakeOpen", 0));//.toFixed(1);
  14. this.sfxToggle.isChecked = this.sfxVolume != 0;
  15. this.bgmToggle.isChecked = this.bgmVolume != 0;
  16. this.shakeToggle.isChecked = this.shakeOpen != 0;
  17. },
  18. playButton() {
  19. this.playEffec("click");
  20. },
  21. playJump() {
  22. this.playEffec("clickjump");
  23. },
  24. playBGM() {
  25. this.isPlayBGM = true;
  26. this.playMusic("crashBgm", true);
  27. },
  28. playBoom() {
  29. this.playEffec("rocketBoom");
  30. },
  31. playStart() {
  32. this.playEffec("rocketStart");
  33. },
  34. playTimeDown() {
  35. this.isPlayBGM = false;
  36. this.playMusic("timedown", false);
  37. },
  38. playEffec(name) {
  39. if (cc.vv && cc.vv.audioMgr) {
  40. cc.vv.audioMgr.playSFX(name);
  41. }
  42. },
  43. playMusic(name, bool) {
  44. if (cc.vv && cc.vv.audioMgr) {
  45. cc.vv.audioMgr.playBGM(name, bool);
  46. }
  47. },
  48. clickSFX() {
  49. this.playButton();
  50. if (cc.vv.audioMgr.sfxVolume > 0) {
  51. cc.vv.audioMgr.setSFXVolume(0, false, true);
  52. } else {
  53. cc.vv.audioMgr.setSFXVolume(1, false, true);
  54. }
  55. },
  56. clickBGM() {
  57. this.playButton();
  58. if (cc.vv.audioMgr.bgmVolume > 0) {
  59. cc.vv.audioMgr.setBGMVolume(0, false, true);
  60. } else {
  61. cc.vv.audioMgr.setBGMVolume(1, false, true);
  62. }
  63. },
  64. clickShake() {
  65. this.playButton();
  66. if (cc.vv.audioMgr.shakeOpen > 0) {
  67. cc.vv.audioMgr.setShakeOpen(0);
  68. } else {
  69. cc.vv.audioMgr.setShakeOpen(1);
  70. }
  71. },
  72. });