FruitSound.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Learn cc.Class:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/class.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. var UIHelper = require("UIHelper");
  8. var Global = require("Global");
  9. cc.Class({
  10. extends: cc.Component,
  11. statics: {
  12. LG_PATH_SC: "LB-Roman/",
  13. bgmAudioID:-1,
  14. btnEff: ["button"],
  15. rewardEff: ["Level01","Level02","Level03","Level04","Level05","Level08","Level09","Level10","Level11","Level12","Level13","Level14","Level15"],
  16. init() {
  17. var self = this;
  18. this.rewardAudio = [];
  19. // UIHelper.loadRes("sounds/SGLB/Level01", cc.AudioClip, function(audioClip){
  20. // self.rewardAudio[1] = audioClip;
  21. // });
  22. for(let i = 0; i < self.rewardEff.length; ++i) {
  23. UIHelper.loadRes("sounds/LB-Public/"+self.rewardEff[i], cc.AudioClip, function(audioClip){
  24. self.rewardAudio[i] = audioClip;
  25. });
  26. }
  27. UIHelper.loadRes("sounds/LB-Roman/freestart", cc.AudioClip, function(audioClip){
  28. self.freeAudio = audioClip;
  29. });
  30. },
  31. playBackMusic(kName) {
  32. var path = this.LG_PATH_SC + kName;
  33. if (cc.vv && cc.vv.audioMgr) {
  34. this.bgmAudioID = cc.vv.audioMgr.playBGM(path);
  35. }
  36. },
  37. pauseBackMusic() {
  38. if (cc.vv && cc.vv.audioMgr) {
  39. cc.vv.audioMgr.pauseBackMusic();
  40. }
  41. },
  42. resumeBackMusic() {
  43. if (cc.vv && cc.vv.audioMgr) {
  44. cc.vv.audioMgr.resumeBackMusic();
  45. }
  46. },
  47. stopBackMusic() {
  48. if (cc.vv && cc.vv.audioMgr) {
  49. cc.vv.audioMgr.stopBackMusic();
  50. }
  51. },
  52. playEffect(kName, preload) {
  53. var path = this.LG_PATH_SC + kName;
  54. if (cc.vv && cc.vv.audioMgr) {
  55. cc.vv.audioMgr.playSFX(path);
  56. }
  57. },
  58. playRewardEffect(id) {
  59. let audio = this.rewardAudio[id];
  60. if(audio) {
  61. return cc.audioEngine.play(audio, false, cc.vv.audioMgr.sfxVolume);
  62. }
  63. return -1;
  64. },
  65. playFreeEffect() {
  66. if(this.freeAudio) {
  67. return cc.audioEngine.play(this.freeAudio, false, cc.vv.audioMgr.sfxVolume);
  68. }
  69. return -1;
  70. },
  71. stopEffectByID(audioID) {
  72. if (audioID >= 0 && cc.vv && cc.vv.audioMgr) {
  73. cc.vv.audioMgr.stopSFX(audioID);
  74. }
  75. },
  76. playEffectArr(kNameArr) {
  77. var kName = kNameArr[0];
  78. if (kNameArr.length > 1) {
  79. var index = Math.floor(Math.random()*1000 % kNameArr.length);
  80. kName = kNameArr[index];
  81. }
  82. this.playEffect(kName);
  83. },
  84. },
  85. });