AudioMng.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. bgm: {
  5. default: null,
  6. url: cc.AudioClip
  7. },
  8. bgmBingo: {
  9. default: null,
  10. url: cc.AudioClip
  11. },
  12. buttonAudio: {
  13. default: null,
  14. url: cc.AudioClip
  15. },
  16. loseAudio: {
  17. default: null,
  18. url: cc.AudioClip
  19. },
  20. enter1Audio: {
  21. default: null,
  22. url: cc.AudioClip
  23. },
  24. enter2Audio: {
  25. default: null,
  26. url: cc.AudioClip
  27. },
  28. enter3Audio: {
  29. default: null,
  30. url: cc.AudioClip
  31. },
  32. shootAudio: {
  33. default: null,
  34. url: cc.AudioClip
  35. },
  36. goldAudio: {
  37. default: null,
  38. url: cc.AudioClip
  39. },
  40. volume: 1
  41. },
  42. onLoad () {
  43. this.currentAudio = {};
  44. },
  45. /**
  46. * 暂停所有音效
  47. */
  48. stopAll () {
  49. cc.audioEngine.stopAll();
  50. },
  51. /**
  52. * 播放背景音乐
  53. */
  54. playBgm () {
  55. this.currentAudio['bgm'] = cc.audioEngine.play(this.bgm, true, this.volume);
  56. },
  57. /**
  58. * 暂停播放背景音乐
  59. */
  60. stopBgm () {
  61. cc.audioEngine.stop(this.currentAudio['bgm']);
  62. },
  63. /**
  64. * 播放华彩模式音乐
  65. */
  66. playBgmBingo () {
  67. this.stopBgm();
  68. this.currentAudio['bgmBingo'] = cc.audioEngine.play(this.bgmBingo, true, this.volume);
  69. },
  70. /**
  71. * 暂停播放华彩模式音乐
  72. */
  73. stopBgmBingo () {
  74. cc.audioEngine.stop(this.currentAudio['bgmBingo']);
  75. },
  76. stopAll () {
  77. cc.audioEngine.stopAll();
  78. },
  79. /**
  80. * 播放失败音乐
  81. */
  82. playLose () {
  83. this.stopBgm();
  84. cc.audioEngine.play(this.loseAudio, false, this.volume);
  85. },
  86. /**
  87. * 播放按钮音效
  88. */
  89. playButton () {
  90. cc.audioEngine.play(this.buttonAudio, false, this.volume);
  91. },
  92. /**
  93. * 播放插中瓶子音效
  94. */
  95. playEnter () {
  96. let ran = Math.floor(cc.random0To1() * 3);
  97. let enterMap = [this.enter1Audio, this.enter2Audio, this.enter3Audio]
  98. cc.audioEngine.play(enterMap[ran], false, this.volume);
  99. },
  100. /**
  101. * 播放获取金币音效
  102. */
  103. playGetGold () {
  104. cc.audioEngine.play(this.goldAudio, false, this.volume);
  105. },
  106. /**
  107. * 播放箭矢发射音效
  108. */
  109. playShoot () {
  110. cc.audioEngine.play(this.shootAudio, false, this.volume);
  111. },
  112. _playSFX: function(clip) {
  113. cc.audioEngine.playEffect( clip, false );
  114. },
  115. // update (dt) {},
  116. });