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. buttonAudio: {
  11. tooltip: '按钮音效',
  12. default: null,
  13. type: cc.AudioClip
  14. },
  15. giftAudio: {
  16. tooltip: '获得奖励音效',
  17. default: null,
  18. type: cc.AudioClip
  19. },
  20. updateBuildingAudio: {
  21. tooltip: '升级建筑音效',
  22. default: null,
  23. type: cc.AudioClip
  24. },
  25. signSuccessAudio: {
  26. tooltip: '抢夺、进阶成功音效',
  27. default: null,
  28. type: cc.AudioClip
  29. },
  30. signFailAudio: {
  31. tooltip: '抢夺、进阶失败音效',
  32. default: null,
  33. type: cc.AudioClip
  34. },
  35. getCoinAudio: {
  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. playButton () {
  74. cc.audioEngine.play(this.buttonAudio, false, this.volume);
  75. },
  76. /**
  77. * 播放获得奖励音效
  78. */
  79. playGift () {
  80. cc.audioEngine.play(this.giftAudio, false, this.volume);
  81. },
  82. /**
  83. * 播放升级建筑音乐
  84. */
  85. playUpdateBuilding () {
  86. cc.audioEngine.play(this.updateBuildingAudio, false, this.volume);
  87. },
  88. /**
  89. * 播放抢夺、进阶成功音效
  90. */
  91. playSignSuccess () {
  92. cc.audioEngine.play(this.signSuccessAudio, false, this.volume);
  93. },
  94. /**
  95. * 播放抢夺、进阶失败音效
  96. */
  97. playSignFail () {
  98. cc.audioEngine.play(this.signFailAudio, false, this.volume);
  99. },
  100. /**
  101. * 播放收取金币音效
  102. */
  103. playGetcoin () {
  104. cc.audioEngine.play(this.getCoinAudio, false, this.volume);
  105. }
  106. // update (dt) {},
  107. });