AudioMng.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. bgm: {
  5. tooltip: '背景音乐',
  6. default: null,
  7. type: cc.AudioClip
  8. },
  9. buttonAudio: {
  10. tooltip: '按钮音效',
  11. default: null,
  12. type: cc.AudioClip
  13. },
  14. giftAudio: {
  15. tooltip: '获得奖励音效',
  16. default: null,
  17. type: cc.AudioClip
  18. },
  19. updateBuildingAudio: {
  20. tooltip: '升级建筑音效',
  21. default: null,
  22. type: cc.AudioClip
  23. },
  24. signSuccessAudio: {
  25. tooltip: '抢夺、进阶成功音效',
  26. default: null,
  27. type: cc.AudioClip
  28. },
  29. signFailAudio: {
  30. tooltip: '抢夺、进阶失败音效',
  31. default: null,
  32. type: cc.AudioClip
  33. },
  34. getCoinAudio: {
  35. tooltip: '收取金币音效',
  36. default: null,
  37. type: cc.AudioClip
  38. },
  39. volume: {
  40. tooltip: '总音量',
  41. default: 1,
  42. type: cc.Integer
  43. }
  44. },
  45. onLoad () {
  46. this.currentAudio = {};
  47. },
  48. /**
  49. * 暂停所有音效
  50. */
  51. stopAll () {
  52. cc.audioEngine.stopAll();
  53. },
  54. /**
  55. * 播放背景音乐
  56. */
  57. playBgm () {
  58. this.currentAudio['bgm'] = cc.audioEngine.play(this.bgm, true, this.volume);
  59. },
  60. /**
  61. * 暂停播放背景音乐
  62. */
  63. stopBgm () {
  64. cc.audioEngine.stop(this.currentAudio['bgm']);
  65. },
  66. /**
  67. * 播放按钮音效
  68. */
  69. playButton () {
  70. cc.audioEngine.play(this.buttonAudio, false, this.volume);
  71. }
  72. // update (dt) {},
  73. });