123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- /**
- * Player场景声音控制
- */
- // let GameEvent = require('GameEvent');
- let GameEvent = require('GameEvent');
- cc.Class({
- extends: cc.Component,
- editor: {
- menu: 'GameAudio(游戏声音脚本)',
- },
- properties: {
- bgmClip: { type: cc.AudioClip, default: null }, //背景音乐
- wowClip: { type: cc.AudioClip, default: null }, //过关音效
- startClip: { type: cc.AudioClip, default: null }, //开始音效
- selectClip: { type: cc.AudioClip, default: null }, //选中音效
- brokens: { type: cc.AudioClip, default: [] }, //消除音效
- popClip: { type: cc.AudioClip, default: null }
- },
- start () {
- zy.playBgMusic(this.bgmClip,true)
- zy.playSound(this.startClip);
- //矩阵事件监听
- cc.game.on(GameEvent.EventType.GAME_CLEAR_COUNT, (count) => {
- let index = Math.min(count - 1, this.brokens.length - 1);
- if(index >= 0) {
- zy.playSound(this.brokens[index]);
- this._playPopEffect(count);
- }
-
- }, this);
- //过关
- cc.game.on(GameEvent.EventType.GAME_PASS_STAGE, () => {
- zy.playSound(this.wowClip);
- }, this);
- },
- _playPopEffect(count) {
- let index = 0;
- let playPopClip = () => {
- ++index;
- zy.playSound(this.popClip);
- if (index >= count) {
- this.unschedule(playPopClip);
- }
- }
- this.schedule(playPopClip, 0.08);
- },
- onDestroy() {
- //关闭所有音乐、音效
- cc.audioEngine.stopAll();
- //移除所有事件监听
- cc.game.targetOff(this);
- }
- });
|