b6d756ce-9346-4388-9d29-38c2394f228f.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. "use strict";
  2. cc._RF.push(module, 'b6d75bOk0ZDiJ0pOMI5TyKP', 'SoundManager');
  3. // Script/Manager/SoundManager.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. Object.defineProperty(exports, "__esModule", { value: true });
  19. exports.SoundManager = void 0;
  20. /**
  21. * 声音管理类
  22. * @author xiongjian
  23. * @date 2016/6/30
  24. */
  25. var SingleClass_1 = require("./SingleClass");
  26. var SoundManager = /** @class */ (function (_super) {
  27. __extends(SoundManager, _super);
  28. function SoundManager() {
  29. var _this = _super.call(this) || this;
  30. _this.soundList = {}; //声音列表
  31. _this.soundActList = {}; //动作列表
  32. _this.actChannelList = {}; //动作音道列表
  33. _this._allowPlayEffect = true; //是否允许播放音效
  34. _this._allowPlayBGM = true; //是否允许播放背景音乐
  35. _this._effectVolume = 1; //音效音量
  36. _this._bgmVolume = 1; //背景音量
  37. _this.jumpID = -1; //跳跃音道
  38. _this.videoEffect = false;
  39. _this.videoMusic = false;
  40. return _this;
  41. }
  42. /**将牌值转换未音效名 */
  43. SoundManager.prototype.changeCardValue = function (cardValue) {
  44. return;
  45. };
  46. /**
  47. * 播放音效
  48. * @param soundName 声音名
  49. * @param loops 循环次数
  50. */
  51. SoundManager.prototype.playEffect = function (soundName, loops) {
  52. var _this = this;
  53. if (loops === void 0) { loops = false; }
  54. if (!this.allowPlayEffect) {
  55. return;
  56. }
  57. //从声音列表中获取,声音列表中不存在,则从加载资源中获取
  58. var sound = this.soundList[soundName];
  59. if (sound == null) {
  60. cc.loader.loadRes("Audio/" + soundName, cc.AudioClip, function (err, audioClip) {
  61. console.log("==>" + typeof audioClip);
  62. _this.soundList[soundName] = audioClip;
  63. _this.EffectAudioID = cc.audioEngine.playEffect(audioClip, loops);
  64. cc.audioEngine.setVolume(_this.EffectAudioID, _this._effectVolume);
  65. });
  66. }
  67. else {
  68. this.EffectAudioID = cc.audioEngine.playEffect(sound, loops);
  69. cc.audioEngine.setVolume(this.EffectAudioID, this._effectVolume);
  70. }
  71. };
  72. /**观看视频音量关闭 */
  73. SoundManager.prototype.VideoStartStop = function () {
  74. this.videoEffect = this._allowPlayEffect;
  75. this.videoMusic = this._allowPlayBGM;
  76. this._allowPlayEffect = false;
  77. this.stopBGM();
  78. };
  79. /**观看视频音量开启*/
  80. SoundManager.prototype.VideoEndOpen = function () {
  81. if (this.videoMusic)
  82. this.playBGM(SoundManager.hallBgm[2]);
  83. this._allowPlayEffect = this.videoEffect;
  84. };
  85. /**
  86. * 停止播放音效
  87. */
  88. SoundManager.prototype.stopEffect = function () {
  89. cc.audioEngine.stopAllEffects();
  90. // if (!this.EffectAudioID) return;
  91. // cc.audioEngine.stopEffect(this.EffectAudioID)
  92. };
  93. /**
  94. * 播放背景音乐
  95. * @param bgmName 背景音名
  96. * @param startTime 播放起始位置
  97. * @param loops 循环次数
  98. */
  99. SoundManager.prototype.playBGM = function (bgmName, loops) {
  100. var _this = this;
  101. if (loops === void 0) { loops = true; }
  102. if (this.allowPlayBGM == false) { // || this.bgmChannelID != null
  103. return;
  104. }
  105. this.stopBGM();
  106. console.log('播放背景音乐:bgmName', bgmName);
  107. var bgm = this.soundList[bgmName];
  108. if (bgm == null) {
  109. cc.loader.loadRes("Audio/" + bgmName, cc.AudioClip, function (err, audioClip) {
  110. console.log("==>" + typeof audioClip);
  111. _this.soundList[bgmName] = audioClip;
  112. // this.bgmChannelID = cc.audioEngine.play(audioClip, loops,this._bgmVolume);
  113. _this.bgmChannelID = cc.audioEngine.playMusic(audioClip, loops);
  114. cc.audioEngine.setVolume(_this.bgmChannelID, _this._bgmVolume);
  115. });
  116. }
  117. if (bgm) {
  118. this.bgmChannelID = cc.audioEngine.playMusic(bgm, loops);
  119. cc.audioEngine.setVolume(this.bgmChannelID, this._bgmVolume);
  120. }
  121. };
  122. /**停止背景音乐*/
  123. SoundManager.prototype.stopBGM = function () {
  124. // if (this.bgmChannelID) {
  125. cc.audioEngine.stopMusic();
  126. // cc.audioEngine.stop(this.bgmChannelID);
  127. this.bgmChannelID = null;
  128. // }
  129. };
  130. /**停止背景音乐*/
  131. SoundManager.prototype.stopClock = function () {
  132. if (this.clockChannelID) {
  133. cc.audioEngine.stop(this.clockChannelID);
  134. this.clockChannelID = null;
  135. }
  136. };
  137. Object.defineProperty(SoundManager.prototype, "allowPlayEffect", {
  138. /**获取是否允许播放音效*/
  139. get: function () {
  140. return this._allowPlayEffect;
  141. },
  142. /**设置是否允许播放音效*/
  143. set: function (bAllow) {
  144. this._allowPlayEffect = bAllow;
  145. },
  146. enumerable: false,
  147. configurable: true
  148. });
  149. Object.defineProperty(SoundManager.prototype, "allowPlayBGM", {
  150. /**获取是否允许播放背景音*/
  151. get: function () {
  152. return this._allowPlayBGM;
  153. },
  154. /**设置是否允许播放背景音*/
  155. set: function (bAllow) {
  156. this._allowPlayBGM = bAllow;
  157. if (this._allowPlayBGM == false) {
  158. this.stopBGM();
  159. }
  160. else {
  161. this.playBGM(SoundManager.hallBgm[0]);
  162. }
  163. },
  164. enumerable: false,
  165. configurable: true
  166. });
  167. Object.defineProperty(SoundManager.prototype, "effectVolume", {
  168. /**获取音效音量*/
  169. get: function () {
  170. return this._effectVolume;
  171. },
  172. /**设置音效音量*/
  173. set: function (value) {
  174. this._effectVolume = value;
  175. },
  176. enumerable: false,
  177. configurable: true
  178. });
  179. Object.defineProperty(SoundManager.prototype, "bgmVolume", {
  180. /**获取BGM音量*/
  181. get: function () {
  182. return this._bgmVolume;
  183. },
  184. /**设置BGM音量*/
  185. set: function (value) {
  186. this._bgmVolume = value;
  187. if (this.bgmChannelID) {
  188. cc.audioEngine.setVolume(this.bgmChannelID, this._bgmVolume);
  189. }
  190. },
  191. enumerable: false,
  192. configurable: true
  193. });
  194. //大厅背景音乐, //菜单背景音乐, //游戏背景音乐
  195. SoundManager.hallBgm = ["bgm_1.mp3", "bgm_2.mp3", "bgm_3.mp3"];
  196. SoundManager.click = "click.mp3"; //按钮点击
  197. SoundManager.start = "start.mp3"; // 开始游戏
  198. SoundManager.addCoin = "addCoin.mp3"; //
  199. SoundManager.cookingOver = "cookingOver.mp3"; //
  200. SoundManager.success = ["success_1.mp3", "success_2.mp3"]; // 胜利音效
  201. SoundManager.fail = "fail_1.mp3"; // 失败音效
  202. return SoundManager;
  203. }(SingleClass_1.SingleClass));
  204. exports.SoundManager = SoundManager;
  205. cc._RF.pop();