AudioMng.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. this.currentAudio['bgm'] = cc.audioEngine.play(this.bgm, true, this.volume);
  63. },
  64. /**
  65. * 暂停播放背景音乐
  66. */
  67. stopBgm () {
  68. cc.audioEngine.stop(this.currentAudio['bgm']);
  69. },
  70. /**
  71. * 播放按钮音效
  72. */
  73. playClickButton () {
  74. cc.audioEngine.play(this.buttonClickAudio, false, this.volume);
  75. },
  76. /**
  77. * 播放获得奖励音效
  78. */
  79. playGetAward () {
  80. cc.audioEngine.play(this.getAwardAudio, false, this.volume);
  81. },
  82. /**
  83. * 播放升级建筑音效
  84. */
  85. playUpdateBuilding () {
  86. cc.audioEngine.play(this.updateBuildingAudio, false, this.volume);
  87. },
  88. /**
  89. * 点击招财猫
  90. */
  91. playClickCat () {
  92. cc.audioEngine.play(this.clickCatAudio, false, this.volume);
  93. },
  94. /**
  95. * 抽奖音效
  96. */
  97. playGetDraw () {
  98. cc.audioEngine.play(this.getDrawAudio, false, this.volume);
  99. },
  100. /**
  101. * 获取到明星音效
  102. */
  103. playGetStar () {
  104. cc.audioEngine.play(this.getStarAudio, false, this.volume);
  105. },
  106. // update (dt) {},
  107. });