AudioMng.js 2.5 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.playBgm();
  50. },
  51. /**
  52. * 暂停所有音效
  53. */
  54. stopAll () {
  55. cc.audioEngine.stopAll();
  56. },
  57. /**
  58. * 播放背景音乐
  59. */
  60. playBgm () {
  61. this.currentAudio['bgm'] = cc.audioEngine.play(this.bgm, true, this.volume);
  62. },
  63. /**
  64. * 暂停播放背景音乐
  65. */
  66. stopBgm () {
  67. cc.audioEngine.stop(this.currentAudio['bgm']);
  68. },
  69. /**
  70. * 播放按钮音效
  71. */
  72. playButton () {
  73. cc.audioEngine.play(this.buttonAudio, false, this.volume);
  74. },
  75. /**
  76. * 播放获得奖励音效
  77. */
  78. playGift () {
  79. cc.audioEngine.play(this.giftAudio, false, this.volume);
  80. },
  81. /**
  82. * 播放升级建筑音乐
  83. */
  84. playUpdateBuilding () {
  85. cc.audioEngine.play(this.updateBuildingAudio, false, this.volume);
  86. },
  87. /**
  88. * 播放抢夺、进阶成功音效
  89. */
  90. playSignSuccess () {
  91. cc.audioEngine.play(this.signSuccessAudio, false, this.volume);
  92. },
  93. /**
  94. * 播放抢夺、进阶失败音效
  95. */
  96. playSignFail () {
  97. cc.audioEngine.play(this.signFailAudio, false, this.volume);
  98. },
  99. /**
  100. * 播放收取金币音效
  101. */
  102. playGetcoin () {
  103. cc.audioEngine.play(this.getCoinAudio, false, this.volume);
  104. }
  105. // update (dt) {},
  106. });