soundManage.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. window.soundM = {
  2. sound : null
  3. }
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. Sound_BGM: {
  8. default: null,
  9. type: cc.AudioClip
  10. },
  11. StartGame_Clip: {
  12. default: null,
  13. type: cc.AudioClip
  14. },
  15. Login_Clip: {
  16. default: null,
  17. type: cc.AudioClip
  18. },
  19. StartToPlayTutorial_Clip:{
  20. default: null,
  21. type: cc.AudioClip
  22. },
  23. Tutorial_Clip:{
  24. default: null,
  25. type: cc.AudioClip
  26. },
  27. Settlement_Clip: {
  28. default: null,
  29. type: cc.AudioClip
  30. },
  31. Close_Clip: {
  32. default: null,
  33. type: cc.AudioClip
  34. },
  35. Score_Clip: {
  36. default: null,
  37. type: cc.AudioClip
  38. },
  39. },
  40. start () {
  41. this.playScoremin = 0;
  42. this.playScoreNum = 0;
  43. this.playScoreMax = 6;
  44. this.schedule(function(){
  45. cc.sys.garbageCollect();
  46. },10);
  47. soundM.sound = this;
  48. this.initBG();
  49. cc.game.on(cc.game.EVENT_HIDE, function(){
  50. console.log("游戏进入后台");
  51. cc.audioEngine.setMusicVolume(0);
  52. },this);
  53. cc.game.on(cc.game.EVENT_SHOW, function(){
  54. console.log("重新返回游戏");
  55. cc.audioEngine.setMusicVolume(0.5);
  56. },this);
  57. },
  58. initBG : function(){
  59. cc.audioEngine.playMusic(this.Sound_BGM,true);
  60. cc.audioEngine.setMusicVolume(0.5);
  61. },
  62. startToPlayTutorial: function () {
  63. this.StartToPlayTutorial_ClipID = cc.audioEngine.play(this.StartToPlayTutorial_Clip,false,1);
  64. return this.StartToPlayTutorial_ClipID;
  65. },
  66. playTutorial: function () {
  67. this.Tutorial_ClipID = cc.audioEngine.play(this.Tutorial_Clip,false,1);
  68. return this.Tutorial_ClipID;
  69. },
  70. playScore: function () {
  71. if (this.playScoreNum <= this.playScoreMax) {
  72. this.playScoreNum++;
  73. }else{
  74. this.Score_ClipID = cc.audioEngine.play(this.Score_Clip,false,0.2);
  75. this.playScoreNum = this.playScoremin;
  76. }
  77. return this.Score_ClipID;
  78. },
  79. playLogin : function () {
  80. this.Login_ClipID = cc.audioEngine.play(this.Login_Clip,false,1);
  81. return this.Login_ClipID;
  82. },
  83. playStartGame : function () {
  84. this.StartGame_ClipID = cc.audioEngine.play(this.StartGame_Clip,false,1);
  85. return this.StartGame_ClipID;
  86. },
  87. playSettlement : function () {
  88. this.Settlement_ClipID = cc.audioEngine.play(this.Settlement_Clip,false,1);
  89. return this.Settlement_ClipID;
  90. },
  91. playClose : function () {
  92. this.Close_ClipID = cc.audioEngine.play(this.Close_Clip,false,1);
  93. return this.Close_ClipID;
  94. },
  95. stopAll : function(){
  96. // this.unschedule(this.findWorkCallback);
  97. cc.audioEngine.stopAll();
  98. },
  99. stopMusic : function(){
  100. // this.unschedule(this.findWorkCallback);
  101. cc.audioEngine.stopMusic();
  102. },
  103. stop : function(ID){
  104. // this.unschedule(this.findWorkCallback);
  105. cc.audioEngine.stop(ID);
  106. },
  107. stopAllSoundEffect : function(){
  108. cc.audioEngine.stop(this.StartToPlayTutorial_ClipID);
  109. cc.audioEngine.stop(this.Tutorial_ClipID);
  110. cc.audioEngine.stop(this.Login_ClipID);
  111. cc.audioEngine.stop(this.StartGame_ClipID);
  112. cc.audioEngine.stop(this.Settlement_ClipID);
  113. cc.audioEngine.stop(this.Close_ClipID);
  114. }
  115. });