| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- cc.Class({
- extends: cc.Component,
- properties: {
- //背景音乐
- // Sound_BGM: {
- // default: null,
- // type: cc.AudioClip
- // },
- //点击普通按钮音效
- Sound_PressBtn: {
- default: null,
- type: cc.AudioClip
- },
- //赚到钱时增加收入时音效
- Sound_GetCoins: {
- default: null,
- type: cc.AudioClip
- },
- //店铺获得销售加成、农舍获取恢复体力加成时的音效
- Sound_BuildingAddition: {
- default: null,
- type: cc.AudioClip
- },
- //建造建筑时的音效
- Sound_FinishBuilding: {
- default: null,
- type: cc.AudioClip
- },
- //员工培训后升级的音效
- Sound_PeopleLevelUp: {
- default: null,
- type: cc.AudioClip
- },
- //招聘到员工时音效
- Sound_Recruit: {
- default: null,
- type: cc.AudioClip
- },
- OnOrOffMusicNode: {
- default: null,
- type: cc.Node,
- },
- OnOrOffSoundNode: {
- default: null,
- type: cc.Node,
- },
- OnImage: cc.SpriteFrame,
- OffImage: cc.SpriteFrame,
- IsMusicOn: true,
- IsSoundOn: true,
- // BGM: null,
- IsDebug: false,
- },
- // PlaySound:function (audioSource) {
- // audioSource.play();
- // },
- // onEnable(){
- // cc.log("cc.audioEngine.isMusicPlaying()",cc.audioEngine.isMusicPlaying())
- // },
- start() {
- // cc.game.on(cc.game.EVENT_SHOW, function () {
- // if (this.IsMusicOn&&this.BGM == 0) {
- // console.log("Play BGM!");
- // cc.audioEngine.resume(this.BGM);
- // }
- //
- // }.bind(this));
- this.IsMusicOn = true;
- this.IsSoundOn = true;
- if (!this.IsDebug) {
- // this.BGM = cc.audioEngine.play(this.Sound_BGM, true, 1);
- // cc.audioEngine.playMusic(this.Sound_BGM,1);
- this.stopAll();
- this.PlayBg();
- }
- UtilsWX.soundManage = this;
- },
- PlayBg : function(){
- if (this.BGM != null) {
- cc.audioEngine.stop(this.BGM);
- }
- cc.loader.loadRes('Sound/Sound_BGM', cc.AudioClip, function(err,clip){
- this.mclip = clip;
- this.BGM = cc.audioEngine.play(clip,false,1);
- }.bind(this));
- this.findWorkCallback = function () {
- // console.log("进来了吗");
- // this.BGM = cc.audioEngine.playMusic(this.mclip, false);
- if (this.BGM != null) {
- cc.audioEngine.stop(this.BGM);
- }
- cc.loader.loadRes('Sound/Sound_BGM', cc.AudioClip, function(err,clip){
- this.mclip = clip;
- this.BGM = cc.audioEngine.play(clip,false,1);
- // console.log("再次播放音乐");
- }.bind(this));
- }.bind(this);
- this.schedule(this.findWorkCallback, 33.4);
- },
- stopBg : function(){
- this.unschedule(this.findWorkCallback);
- cc.audioEngine.stop(this.BGM);
- },
- stopAll : function(){
- this.unschedule(this.findWorkCallback);
- cc.audioEngine.stopAll();
- },
- PlayPressBtn: function () {
- this.PlaySoundEffect(this.Sound_PressBtn, false, 1);
- },
- PlayGetCoins: function () {
- this.PlaySoundEffect(this.Sound_GetCoins, false, 1);
- },
- PlayBuildingAddition: function () {
- this.PlaySoundEffect(this.Sound_BuildingAddition, false, 1);
- },
- PlayFinishBuilding: function () {
- this.PlaySoundEffect(this.Sound_FinishBuilding, false, 1);
- },
- PlayPeopleLevelUp: function () {
- this.PlaySoundEffect(this.Sound_PeopleLevelUp, false, 1);
- },
- PlayRecruit: function () {
- this.PlaySoundEffect(this.Sound_Recruit, false, 1);
- },
- PlaySoundEffect: function (SoundEffect, IsLoop, Volume) {
- if (this.IsSoundOn) {
- cc.audioEngine.play(SoundEffect, IsLoop, Volume);
- }
- },
- PauseOrResumeSoundEffect: function () {
- if (this.IsSoundOn) {
- this.IsSoundOn = false;
- this.OnOrOffSoundNode.getComponent(cc.Sprite).spriteFrame = this.OffImage;
- } else {
- this.IsSoundOn = true;
- this.OnOrOffSoundNode.getComponent(cc.Sprite).spriteFrame = this.OnImage;
- }
- },
- PauseOrResumeMusic: function () {
- if (this.IsMusicOn) {
- this.IsMusicOn = false;
- // cc.audioEngine.pause(this.BGM);
- this.stopBg();
- this.OnOrOffMusicNode.getComponent(cc.Sprite).spriteFrame = this.OffImage;
- }
- else {
- this.IsMusicOn = true;
- // cc.audioEngine.resume(this.BGM);
- this.PlayBg();
- this.OnOrOffMusicNode.getComponent(cc.Sprite).spriteFrame = this.OnImage;
- }
- },
- startVideo: function () {
- if (this.IsMusicOn) {
- // cc.audioEngine.pause(this.BGM);
- this.PlayBg();
- // this.OnOrOffMusicNode.getComponent(cc.Sprite).spriteFrame = this.OffImage;
- }
- },
- stopVideo: function () {
- if (this.IsMusicOn) {
- // cc.audioEngine.resume(this.BGM);
- this.stopBg();
- // this.OnOrOffMusicNode.getComponent(cc.Sprite).spriteFrame = this.OnImage;
- }
- },
- // onLoad: function () {
- // this.current = cc.audioEngine.play(this.Sound_PressBtn, false, 1);
- // },
- //
- // onDestroy: function () {
- // cc.audioEngine.stop(this.current);
- // }
- });
|