e7bb68d2-cc57-4091-9dcd-13d514d2fb82.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. "use strict";
  2. cc._RF.push(module, 'e7bb6jSzFdAkZ3NE9UU0vuC', 'GameAudio');
  3. // Script/GameAudio.js
  4. "use strict";
  5. /**
  6. * Player场景声音控制
  7. */
  8. // let GameEvent = require('GameEvent');
  9. var GameEvent = require('GameEvent');
  10. cc.Class({
  11. "extends": cc.Component,
  12. editor: {
  13. menu: 'GameAudio(游戏声音脚本)'
  14. },
  15. properties: {
  16. bgmClip: {
  17. type: cc.AudioClip,
  18. "default": null
  19. },
  20. //背景音乐
  21. wowClip: {
  22. type: cc.AudioClip,
  23. "default": null
  24. },
  25. //过关音效
  26. startClip: {
  27. type: cc.AudioClip,
  28. "default": null
  29. },
  30. //开始音效
  31. selectClip: {
  32. type: cc.AudioClip,
  33. "default": null
  34. },
  35. //选中音效
  36. brokens: {
  37. type: cc.AudioClip,
  38. "default": []
  39. },
  40. //消除音效
  41. popClip: {
  42. type: cc.AudioClip,
  43. "default": null
  44. }
  45. },
  46. start: function start() {
  47. var _this = this;
  48. zy.playBgMusic(this.bgmClip, true);
  49. zy.playSound(this.startClip); //矩阵事件监听
  50. cc.game.on(GameEvent.EventType.GAME_CLEAR_COUNT, function (count) {
  51. var index = Math.min(count - 1, _this.brokens.length - 1);
  52. if (index >= 0) {
  53. zy.playSound(_this.brokens[index]);
  54. _this._playPopEffect(count);
  55. }
  56. }, this); //过关
  57. cc.game.on(GameEvent.EventType.GAME_PASS_STAGE, function () {
  58. zy.playSound(_this.wowClip);
  59. }, this);
  60. },
  61. _playPopEffect: function _playPopEffect(count) {
  62. var _this2 = this;
  63. var index = 0;
  64. var playPopClip = function playPopClip() {
  65. ++index;
  66. zy.playSound(_this2.popClip);
  67. if (index >= count) {
  68. _this2.unschedule(playPopClip);
  69. }
  70. };
  71. this.schedule(playPopClip, 0.08);
  72. },
  73. onDestroy: function onDestroy() {
  74. //关闭所有音乐、音效
  75. cc.audioEngine.stopAll(); //移除所有事件监听
  76. cc.game.targetOff(this);
  77. }
  78. });
  79. cc._RF.pop();