Commit 50583886 authored by 范雪寒's avatar 范雪寒

feat: global变量问题

parent d51018ee
...@@ -13,6 +13,7 @@ var game = cc.Class({ ...@@ -13,6 +13,7 @@ var game = cc.Class({
}, },
ctor: function () { ctor: function () {
initGlobal_NGT_02();
game.inst = this; game.inst = this;
g.game = game; g.game = game;
}, },
......
// 全局环境预声明 // 全局环境预声明
window.g = window.g || {}; // 全局 function initGlobal_NGT_02() {
console.log('window.g init');
console.log('window.g init'); window.g = {};
\ No newline at end of file initDataMgr_NGT_02();
initEventMgr_NGT_02();
initStorageMgr_NGT_02();
initResMgr_NGT_02();
initSndMgr_NGT_02();
}
\ No newline at end of file
/** /**
* 数据管理器 * 数据管理器
*/ */
g.data_mgr = { function initDataMgr_NGT_02() {
data: null,//表所有数据 g.data_mgr = {
data: null, //表所有数据
nowNum: null,//剩余个数
nowNum: null, //剩余个数
ansId: null,//问题ID
startId: null,//星星id ansId: null, //问题ID
startId: null, //星星id
nowAnsId: null,//当前星星的问题
nowAnsId: null, //当前星星的问题
gameState: 2,//游戏状态1可操作 2不可操作
gameState: 2, //游戏状态1可操作 2不可操作
nodPlayer: null,//当前播放节点
//获得默认数据 nodPlayer: null, //当前播放节点
getDefaultData() { //获得默认数据
//http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3 getDefaultData() {
const dataJson = { //http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3
"starArr": [{ const dataJson = {
"queArr": [{ starArr: [
"bgItem": { {
"url": "http://staging-teach.cdn.ireadabc.com/bb4244d166b6d077617ff089f7fd46c4.png", "rect": { "x": 259.9654545454546, "y": 0, "width": 377.0690909090909, "height": 373 } queArr: [
}, "hotZoneItemArr": [{ {
"audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3", bgItem: {
"index": 0, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": -1.97, "y": 112, "width": 95.01, "height": 95.01 } url: "http://staging-teach.cdn.ireadabc.com/bb4244d166b6d077617ff089f7fd46c4.png",
}, { rect: {
"audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3", x: 259.9654545454546,
"index": 1, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": 311.03, "y": 118, "width": 77.01, "height": 77.01 } y: 0,
}], "title": "3434", "title_audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3" width: 377.0690909090909,
}, { height: 373,
"bgItem": { },
"url": "http://staging-teach.cdn.ireadabc.com/685ead5fe409d20412a38aae23c75ad0.png", "rect": { "x": 116.9444444444444, "y": -2.842170943040401e-14, "width": 663.1111111111112, "height": 373.00000000000006 } },
}, "hotZoneItemArr": [{ hotZoneItemArr: [
"audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3", {
"index": 0, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": 72.06, "y": 52, "width": 133, "height": 49 } audio_url:
}, { "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3",
"audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3", index: 0,
"index": 1, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": 475.06, "y": 30, "width": 159, "height": 67 } itemType: "rect",
}], "title": "666", "title_audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3" fontSize: 50,
}] fontName: "BRLNSR_1",
}, { fontColor: "#8f3758",
"queArr": [{ fontScale: 0.70078125,
"bgItem": { "url": "http://staging-teach.cdn.ireadabc.com/6326a8bc4896aaa1834bd35f2dac9fee.png", "rect": { "x": 273.3030303030303, "y": 0, "width": 350.3939393939394, "height": 373 } }, imgScale: 1,
"hotZoneItemArr": [{ mapScale: 0.70078125,
"audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3", "index": 0, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": -5.3, "y": 214, "width": 65, "height": 65 } rect: { x: -1.97, y: 112, width: 95.01, height: 95.01 },
}, { "audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3", "index": 1, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": 294.7, "y": 148, "width": 71, "height": 71 } }], "title": "455", "title_audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3" },
}, { {
"bgItem": { "url": "http://staging-teach.cdn.ireadabc.com/942fb8d28620d46d6c77d18909e86806.png", "rect": { "x": 116.9444444444444, "y": -2.842170943040401e-14, "width": 663.1111111111112, "height": 373.00000000000006 } }, audio_url:
"hotZoneItemArr": [{ "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3",
"audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3", "index": 0, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": 247.06, "y": 217, "width": 97, "height": 97 } index: 1,
}, { itemType: "rect",
"audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3", "index": 1, "itemType": "rect", "fontSize": 50, "fontName": "BRLNSR_1", "fontColor": "#8f3758", "fontScale": 0.70078125, "imgScale": 1, "mapScale": 0.70078125, "rect": { "x": 515.06, "y": 108, "width": 57, "height": 57 } fontSize: 50,
}], "title": "7777", "title_audio_url": "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3" fontName: "BRLNSR_1",
}] fontColor: "#8f3758",
}] fontScale: 0.70078125,
} imgScale: 1,
const data = dataJson; mapScale: 0.70078125,
// const data = JSON.parse(dataJson); rect: { x: 311.03, y: 118, width: 77.01, height: 77.01 },
// const data = []; },
return data; ],
}, title: "3434",
title_audio_url:
//获得标题 "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3",
getTitle() { },
return this.data.title; {
}, bgItem: {
url: "http://staging-teach.cdn.ireadabc.com/685ead5fe409d20412a38aae23c75ad0.png",
//获得表单信息 rect: {
getSheepfoldArr() { x: 116.9444444444444,
return this.data.sheepfoldArr; y: -2.842170943040401e-14,
}, width: 663.1111111111112,
height: 373.00000000000006,
//获得表单信息 },
getSheepfold(num) { },
return this.data.sheepfoldArr[num]; hotZoneItemArr: [
}, {
audio_url:
//获得所有选项 "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3",
getSheepArr() { index: 0,
return this.data.sheepArr; itemType: "rect",
}, fontSize: 50,
fontName: "BRLNSR_1",
//获得单项信息 fontColor: "#8f3758",
getSheep(num) { fontScale: 0.70078125,
return this.data.sheepArr[num]; imgScale: 1,
}, mapScale: 0.70078125,
rect: { x: 72.06, y: 52, width: 133, height: 49 },
//获取当前整页数据 },
getPageInfo: function () { {
return this.data.contentObj.pageArr[this.pageId].pageInfo; audio_url:
}, "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3",
index: 1,
//获得整条数据 itemType: "rect",
getResultInfo: function (id) { fontSize: 50,
var pageInfo = this.data.contentObj.pageArr[this.pageId].pageInfo; fontName: "BRLNSR_1",
return pageInfo[id]; fontColor: "#8f3758",
}, fontScale: 0.70078125,
imgScale: 1,
//处理数据 mapScale: 0.70078125,
proGameData: function () { rect: { x: 475.06, y: 30, width: 159, height: 67 },
this.preload(); },
console.log("数据处理完毕:"); ],
}, title: "666",
title_audio_url:
preload() { "http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3",
cc.assetManager.loadAny(null, null, null, (err, data) => { },
//结束回调 ],
this.loadEnd(); },
if (window && window["air"]) { {
window["air"].hideAirClassLoading(); queArr: [
} {
bgItem: {
cc.debug.setDisplayStats(false); url: "http://staging-teach.cdn.ireadabc.com/6326a8bc4896aaa1834bd35f2dac9fee.png",
}); rect: {
}, x: 273.3030303030303,
loadEnd() { y: 0,
//更新游戏界面信息 width: 350.3939393939394,
g.game.inst.UpdataUi(); height: 373,
},
g.game.inst.isLoadEnd = true; },
}, hotZoneItemArr: [
} {
\ No newline at end of file audio_url:
"http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3",
index: 0,
itemType: "rect",
fontSize: 50,
fontName: "BRLNSR_1",
fontColor: "#8f3758",
fontScale: 0.70078125,
imgScale: 1,
mapScale: 0.70078125,
rect: { x: -5.3, y: 214, width: 65, height: 65 },
},
{
audio_url:
"http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3",
index: 1,
itemType: "rect",
fontSize: 50,
fontName: "BRLNSR_1",
fontColor: "#8f3758",
fontScale: 0.70078125,
imgScale: 1,
mapScale: 0.70078125,
rect: { x: 294.7, y: 148, width: 71, height: 71 },
},
],
title: "455",
title_audio_url:
"http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3",
},
{
bgItem: {
url: "http://staging-teach.cdn.ireadabc.com/942fb8d28620d46d6c77d18909e86806.png",
rect: {
x: 116.9444444444444,
y: -2.842170943040401e-14,
width: 663.1111111111112,
height: 373.00000000000006,
},
},
hotZoneItemArr: [
{
audio_url:
"http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3",
index: 0,
itemType: "rect",
fontSize: 50,
fontName: "BRLNSR_1",
fontColor: "#8f3758",
fontScale: 0.70078125,
imgScale: 1,
mapScale: 0.70078125,
rect: { x: 247.06, y: 217, width: 97, height: 97 },
},
{
audio_url:
"http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3",
index: 1,
itemType: "rect",
fontSize: 50,
fontName: "BRLNSR_1",
fontColor: "#8f3758",
fontScale: 0.70078125,
imgScale: 1,
mapScale: 0.70078125,
rect: { x: 515.06, y: 108, width: 57, height: 57 },
},
],
title: "7777",
title_audio_url:
"http://staging-teach.cdn.ireadabc.com/e3921a16a8313df274d8bc4e3f2bedd8.mp3",
},
],
},
],
};
const data = dataJson;
// const data = JSON.parse(dataJson);
// const data = [];
return data;
},
//获得标题
getTitle() {
return this.data.title;
},
//获得表单信息
getSheepfoldArr() {
return this.data.sheepfoldArr;
},
//获得表单信息
getSheepfold(num) {
return this.data.sheepfoldArr[num];
},
//获得所有选项
getSheepArr() {
return this.data.sheepArr;
},
//获得单项信息
getSheep(num) {
return this.data.sheepArr[num];
},
//获取当前整页数据
getPageInfo: function () {
return this.data.contentObj.pageArr[this.pageId].pageInfo;
},
//获得整条数据
getResultInfo: function (id) {
var pageInfo = this.data.contentObj.pageArr[this.pageId].pageInfo;
return pageInfo[id];
},
//处理数据
proGameData: function () {
this.preload();
console.log("数据处理完毕:");
},
preload() {
cc.assetManager.loadAny(null, null, null, (err, data) => {
//结束回调
this.loadEnd();
if (window && window["air"]) {
window["air"].hideAirClassLoading();
}
cc.debug.setDisplayStats(false);
});
},
loadEnd() {
//更新游戏界面信息
g.game.inst.UpdataUi();
g.game.inst.isLoadEnd = true;
},
};
}
// 事件汞 function initEventMgr_NGT_02() {
let eventList = {}; // 响应列表(元素结构:eventName,[[target:cb]]) // 事件汞
g.event_mgr = { let eventList = {}; // 响应列表(元素结构:eventName,[[target:cb]])
// 注册事件-响应 入参:事件名、响应、目标名 g.event_mgr = {
reg: function (eventName, cb, target) { // 注册事件-响应 入参:事件名、响应、目标名
var event = eventList[eventName]; reg: function (eventName, cb, target) {
if (!event) { var event = eventList[eventName];
event = eventList[eventName] = {}; if (!event) {
} event = eventList[eventName] = {};
event[target] = cb; }
}, event[target] = cb;
// 注销事件-响应 入参:事件名、目标名 },
unReg: function (eventName, target) { // 注销事件-响应 入参:事件名、目标名
var event = eventList[eventName]; unReg: function (eventName, target) {
if (event) { var event = eventList[eventName];
if (event[target]) { if (event) {
event[target] = null; if (event[target]) {
} event[target] = null;
} }
}, }
unRegName: function (eventName) { },
eventList[eventName] = {}; unRegName: function (eventName) {
}, eventList[eventName] = {};
// 广播事件 入参:事件名、参数 },
send: function (eventName, params) { // 广播事件 入参:事件名、参数
var event = eventList[eventName]; send: function (eventName, params) {
if (event) { var event = eventList[eventName];
for (var target in event) { if (event) {
var cb = event[target]; for (var target in event) {
if (cb) { var cb = event[target];
cb(params); if (cb) {
} cb(params);
} }
} }
}, }
getReglist: function () { },
return eventList; getReglist: function () {
} return eventList;
}; },
\ No newline at end of file };
}
// localStorage封装 function initStorageMgr_NGT_02() {
g.local_storage = { // localStorage封装
g.local_storage = {
// 背景音乐音量 // 背景音乐音量
getMusicVolume: function () { getMusicVolume: function () {
var vol = cc.sys.localStorage.getItem("music"); var vol = cc.sys.localStorage.getItem("music");
return vol; return vol;
}, },
setMusicVolume: function (vol) { setMusicVolume: function (vol) {
cc.sys.localStorage.setItem('music', vol) cc.sys.localStorage.setItem("music", vol);
}, },
// 音效音量 // 音效音量
getEffectsVolume: function () { getEffectsVolume: function () {
var vol = cc.sys.localStorage.getItem("effect"); var vol = cc.sys.localStorage.getItem("effect");
return vol; return vol;
}, },
setEffectsVolume: function (vol) { setEffectsVolume: function (vol) {
cc.sys.localStorage.setItem('effect', vol); cc.sys.localStorage.setItem("effect", vol);
}, },
}; };
}
/** function initResMgr_NGT_02() {
* 资源管理器 /**
*/ * 资源管理器
g.res_mgr = { */
//获得表数据数据 g.res_mgr = {
getFormData() { //获得表数据数据
console.log('初始化数据'); getFormData() {
console.log("初始化数据");
if (window && window.courseware) {
window.courseware.getData((res) => {
//存入数据管理器
g.data_mgr.data = res;
//数据处理
g.data_mgr.proGameData();
console.log("获得表单数据:" + res);
});
return;
}
const middleLayer = cc.find('middleLayer'); if (window && window.courseware) {
if (middleLayer) { window.courseware.getData((res) => {
const middleLayerComponent = middleLayer.getComponent('middleLayer'); //存入数据管理器
middleLayerComponent.getData((res) => { g.data_mgr.data = res;
//存入数据管理器 //数据处理
g.data_mgr.data = res; g.data_mgr.proGameData();
//数据处理 console.log("获得表单数据:" + res);
g.data_mgr.proGameData(); });
console.log("获得表单数据:" + res); return;
}); }
return;
}
//console.error('没有查找到courseware.getData方法', error); const middleLayer = cc.find("middleLayer");
//获得默认数据 if (middleLayer) {
g.data_mgr.data = g.data_mgr.getDefaultData(); const middleLayerComponent = middleLayer.getComponent("middleLayer");
//数据处理 middleLayerComponent.getData((res) => {
g.data_mgr.proGameData(); //存入数据管理器
}, g.data_mgr.data = res;
//数据处理
g.data_mgr.proGameData();
console.log("获得表单数据:" + res);
});
return;
}
//得到图片资源 //console.error('没有查找到courseware.getData方法', error);
getSpriteFrimeByUrl(url, cb) { //获得默认数据
cc.assetManager.loadRemote(url, cc.SpriteFrame, (e, sp) => { g.data_mgr.data = g.data_mgr.getDefaultData();
const spriteFrame = new cc.SpriteFrame(sp) //数据处理
cb && cb(spriteFrame); g.data_mgr.proGameData();
}); },
},
playAudioByUrl(audio_url, cb) { //得到图片资源
if (audio_url) { getSpriteFrimeByUrl(url, cb) {
cc.assetManager.loadRemote(audio_url, (err, audioClip) => { cc.assetManager.loadRemote(url, cc.SpriteFrame, (e, sp) => {
cb && cb(audioClip); const spriteFrame = new cc.SpriteFrame(sp);
}); cb && cb(spriteFrame);
} });
}, },
//加载龙骨 playAudioByUrl(audio_url, cb) {
loadSpine(animationDisplay, Info) { if (audio_url) {
if (Info.type == 'Image') { cc.assetManager.loadRemote(audio_url, (err, audioClip) => {
return; cb && cb(audioClip);
} });
cc.assetManager.loadAny([{ url: Info.tex_json, ext: '.txt' }, { url: Info.ske_json, ext: '.txt' }], (error, assets) => { }
if (error) { },
console.log(error)
}
else {
cc.assetManager.loadRemote(Info.tex_png, (error, texture) => {
if (error) {
console.log(error)
}
else {
var atlas = new dragonBones.DragonBonesAtlasAsset();
atlas._uuid = Info.tex_json;
atlas.atlasJson = assets[0];
atlas.texture = texture;
var asset = new dragonBones.DragonBonesAsset(); //加载龙骨
asset._uuid = Info.ske_json; loadSpine(animationDisplay, Info) {
asset.dragonBonesJson = assets[1]; if (Info.type == "Image") {
return;
}
cc.assetManager.loadAny(
[
{ url: Info.tex_json, ext: ".txt" },
{ url: Info.ske_json, ext: ".txt" },
],
(error, assets) => {
if (error) {
console.log(error);
} else {
cc.assetManager.loadRemote(Info.tex_png, (error, texture) => {
if (error) {
console.log(error);
} else {
var atlas = new dragonBones.DragonBonesAtlasAsset();
atlas._uuid = Info.tex_json;
atlas.atlasJson = assets[0];
atlas.texture = texture;
animationDisplay.dragonAtlasAsset = atlas; var asset = new dragonBones.DragonBonesAsset();
animationDisplay.dragonAsset = asset; asset._uuid = Info.ske_json;
let data = asset._dragonBonesJsonData.armature[0]; asset.dragonBonesJson = assets[1];
if (!data) {
return;
}
animationDisplay.armatureName = data.name;
g.data_mgr.dragonName = data.animation[0].name;
animationDisplay.node.active = true; animationDisplay.dragonAtlasAsset = atlas;
} animationDisplay.dragonAsset = asset;
}); let data = asset._dragonBonesJsonData.armature[0];
} if (!data) {
}); return;
}, }
} animationDisplay.armatureName = data.name;
\ No newline at end of file g.data_mgr.dragonName = data.animation[0].name;
animationDisplay.node.active = true;
}
});
}
}
);
},
};
}
// 声音管理器 function initSndMgr_NGT_02() {
g.snd_mgr = { // 声音管理器
bgmId: -1, // 背景音乐的音频ID g.snd_mgr = {
effIds: [], // 音效的音频ID列表(由cc.audioEngine保证音频ID不重复) bgmId: -1, // 背景音乐的音频ID
bgmVol: 1, // 背景音乐音量 effIds: [], // 音效的音频ID列表(由cc.audioEngine保证音频ID不重复)
neweffId: null, //保存上一个音效ID bgmVol: 1, // 背景音乐音量
effVol: 1, // 音效音量 neweffId: null, //保存上一个音效ID
pausebgVol: 1, effVol: 1, // 音效音量
pauseeffVol: 1, pausebgVol: 1,
sndNativeUrls: {}, pauseeffVol: 1,
newsnd: null, sndNativeUrls: {},
init: function () { newsnd: null,
var local_storage = g.local_storage; init: function () {
var music_vol = local_storage.getMusicVolume(); var local_storage = g.local_storage;
var effect_vol = local_storage.getEffectsVolume(); var music_vol = local_storage.getMusicVolume();
music_vol != undefined && music_vol + "" != "" && this.setMusicVolume(music_vol); var effect_vol = local_storage.getEffectsVolume();
effect_vol != undefined && effect_vol + "" != "" && this.setEffectsVolume(effect_vol); music_vol != undefined &&
}, music_vol + "" != "" &&
delAudId: function (id) { this.setMusicVolume(music_vol);
if (id == this.bgmId) { effect_vol != undefined &&
this.bgmId = -1; effect_vol + "" != "" &&
return; this.setEffectsVolume(effect_vol);
} },
for (var i = 0; i < this.effIds.length; ++i) { delAudId: function (id) {
if (this.effIds[i] == id) { if (id == this.bgmId) {
this.effIds.splice(i, 1); this.bgmId = -1;
return; return;
} }
} for (var i = 0; i < this.effIds.length; ++i) {
}, if (this.effIds[i] == id) {
playMusic: function (snd, _loop, finishCB) { this.effIds.splice(i, 1);
if (!snd) return; return;
this.newsnd = snd; }
var loop = _loop ? false : true; // 除非指定为false,否则默认为true }
// if (g.configs.platform == "vo") { },
// this.bgmId = cc.audioEngine.play(snd, loop); playMusic: function (snd, _loop, finishCB) {
// return; if (!snd) return;
// } this.newsnd = snd;
cc.audioEngine.stop() var loop = _loop ? false : true; // 除非指定为false,否则默认为true
this.bgmId = cc.audioEngine.playMusic(snd, loop); // if (g.configs.platform == "vo") {
// 播放完成回调 // this.bgmId = cc.audioEngine.play(snd, loop);
if (finishCB) { // return;
cc.audioEngine.setFinishCallback(this.bgmId, function () { // }
finishCB(); cc.audioEngine.stop();
}); this.bgmId = cc.audioEngine.playMusic(snd, loop);
} // 播放完成回调
}, if (finishCB) {
playEffect: function (snd, finishCB) { cc.audioEngine.setFinishCallback(this.bgmId, function () {
if (!snd || this.effVol == 0) return; finishCB();
var id = cc.audioEngine.playEffect(snd, false); // 音效限定不能重复播放 });
this.playaudioEffect(id, finishCB); }
}, },
//播放音效 playEffect: function (snd, finishCB) {
playaudioEffect: function (id, finishCB) { if (!snd || this.effVol == 0) return;
var self = this; var id = cc.audioEngine.playEffect(snd, false); // 音效限定不能重复播放
this.neweffId = id; this.playaudioEffect(id, finishCB);
this.effIds.push(id); },
// 播放完记得删ID //播放音效
cc.audioEngine.setFinishCallback(id, function () { playaudioEffect: function (id, finishCB) {
self.delAudId(id); var self = this;
finishCB && finishCB(); this.neweffId = id;
}); this.effIds.push(id);
}, // 播放完记得删ID
pauseVolume: function () { cc.audioEngine.setFinishCallback(id, function () {
cc.audioEngine.stopAll(); self.delAudId(id);
}, finishCB && finishCB();
resumeVolume: function () { });
if (this.newsnd != null) { },
cc.audioEngine.playMusic(this.newsnd) pauseVolume: function () {
} cc.audioEngine.stopAll();
}, },
setMusicVolume: function (percent) { resumeVolume: function () {
this.bgmVol = percent; if (this.newsnd != null) {
cc.audioEngine.setMusicVolume(~~percent); cc.audioEngine.playMusic(this.newsnd);
}, }
setEffectsVolume: function (percent) { },
this.effVol = percent; setMusicVolume: function (percent) {
cc.audioEngine.setEffectsVolume(~~percent); this.bgmVol = percent;
cc.audioEngine.setMusicVolume(~~this.bgmVol); cc.audioEngine.setMusicVolume(~~percent);
}, },
}; setEffectsVolume: function (percent) {
\ No newline at end of file this.effVol = percent;
cc.audioEngine.setEffectsVolume(~~percent);
cc.audioEngine.setMusicVolume(~~this.bgmVol);
},
};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment