AudioMng.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. const GameModule = require("../utils/GameModule");
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. bgm: {
  6. tooltip: '背景音乐',
  7. default: null,
  8. type: cc.AudioClip
  9. },
  10. buttonClickAudio: {
  11. tooltip: '普通按钮点击音效',
  12. default: null,
  13. type: cc.AudioClip
  14. },
  15. getAwardAudio: {
  16. tooltip: '获得技能、奖励音效',
  17. default: null,
  18. type: cc.AudioClip
  19. },
  20. updateBuildingAudio: {
  21. tooltip: '升级或解锁建筑,购买明星音效',
  22. default: null,
  23. type: cc.AudioClip
  24. },
  25. clickCatAudio: {
  26. tooltip: '点击招财猫音效',
  27. default: null,
  28. type: cc.AudioClip
  29. },
  30. getDrawAudio: {
  31. tooltip: '抽奖音效',
  32. default: null,
  33. type: cc.AudioClip
  34. },
  35. getStarAudio: {
  36. tooltip: '获得明星音效',
  37. default: null,
  38. type: cc.AudioClip
  39. },
  40. volume: {
  41. tooltip: '总音量',
  42. default: 1,
  43. type: cc.Integer
  44. }
  45. },
  46. onLoad () {
  47. GameModule.audioMng = this;
  48. this.currentAudio = {};
  49. this.stopAll();
  50. this.playBgm();
  51. },
  52. /**
  53. * 暂停所有音效
  54. */
  55. stopAll () {
  56. cc.audioEngine.stopAll();
  57. },
  58. /**
  59. * 播放背景音乐
  60. */
  61. playBgm () {
  62. cc.audioEngine.stop(this.currentAudio['bgm']);
  63. this.currentAudio['bgm'] = cc.audioEngine.play(this.bgm, true, this.volume);
  64. },
  65. /**
  66. * 停止播放背景音乐
  67. */
  68. pauseBgm () {
  69. cc.audioEngine.pause(this.currentAudio['bgm']);
  70. },
  71. /**
  72. * 暂停播放背景音乐
  73. */
  74. stopBgm () {
  75. cc.audioEngine.stop(this.currentAudio['bgm']);
  76. },
  77. /**
  78. * 播放按钮音效
  79. */
  80. playClickButton () {
  81. cc.audioEngine.play(this.buttonClickAudio, false, this.volume);
  82. },
  83. /**
  84. * 播放获得奖励音效
  85. */
  86. playGetAward () {
  87. cc.audioEngine.play(this.getAwardAudio, false, this.volume);
  88. },
  89. /**
  90. * 播放升级建筑音效
  91. */
  92. playUpdateBuilding () {
  93. cc.audioEngine.play(this.updateBuildingAudio, false, this.volume);
  94. },
  95. /**
  96. * 点击招财猫
  97. */
  98. playClickCat () {
  99. cc.audioEngine.play(this.clickCatAudio, false, this.volume);
  100. },
  101. /**
  102. * 抽奖音效
  103. */
  104. playGetDraw () {
  105. cc.audioEngine.play(this.getDrawAudio, false, this.volume);
  106. },
  107. /**
  108. * 获取到明星音效
  109. */
  110. playGetStar () {
  111. cc.audioEngine.play(this.getStarAudio, false, this.volume);
  112. },
  113. // update (dt) {},
  114. });