65 lines
2.3 KiB
TypeScript
65 lines
2.3 KiB
TypeScript
import Common from "../common/Common";
|
|
import Define from "../common/Define";
|
|
import UserInfo from "../UserInfo";
|
|
import ResManager from "./ResManager";
|
|
|
|
// Learn TypeScript:
|
|
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
|
|
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
|
|
// Learn Attribute:
|
|
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
|
|
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
|
|
// Learn life-cycle callbacks:
|
|
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
|
|
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
|
|
|
|
const {ccclass, property} = cc._decorator;
|
|
|
|
@ccclass
|
|
export default class SoundManager {
|
|
|
|
static audioSourceArr:cc.AudioSource[] = []
|
|
public static palySoundById(soundId:number,isLoop:boolean = false){
|
|
|
|
ResManager.loadSound(1,function(clip:cc.AudioClip){
|
|
if(clip != null){
|
|
let audioSource:cc.AudioSource = new cc.Node(soundId.toString()).addComponent<cc.AudioSource>(cc.AudioSource);
|
|
audioSource.clip = clip
|
|
|
|
audioSource.loop = isLoop
|
|
audioSource.volume = 0.5
|
|
audioSource.stop();
|
|
audioSource.play();
|
|
SoundManager.audioSourceArr[soundId] = audioSource
|
|
}
|
|
}.bind(this))
|
|
/*
|
|
let audioSource = Common.nodeSoundRoot.children[soundId].getComponent<cc.AudioSource>(cc.AudioSource)
|
|
if(audioSource != null){
|
|
console.log("ss 00")
|
|
audioSource.loop = isLoop
|
|
audioSource.stop();
|
|
audioSource.play();
|
|
SoundManager.audioSourceArr[soundId] = audioSource
|
|
}*/
|
|
}
|
|
|
|
public static pauseBackGroundSound(isPause){
|
|
let sound = SoundManager.audioSourceArr[Define.soundBackgound]
|
|
if(isPause){
|
|
if(sound != null){
|
|
sound.pause();
|
|
console.log("暂停音乐")
|
|
}
|
|
}else{
|
|
if(sound != null){
|
|
sound.resume();
|
|
}else{
|
|
console.log("ss")
|
|
SoundManager.palySoundById(Define.soundBackgound,true);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|