Commit b65ff0d2 authored by wjf's avatar wjf

l

parent 37966fde
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<!-- 易盾js --> <!-- 易盾js -->
<!-- <script type="text/javascript" src="//cstaticdun.126.net/load.min.js"></script> --> <!-- <script type="text/javascript" src="//cstaticdun.126.net/load.min.js"></script> -->
<script src="libs/zepto.min.js"></script> <script src="libs/zepto.min.js"></script>
<script src="//yun.duiba.com.cn/db_games/libs/howler.min.js"></script> <!-- <script src="//yun.duiba.com.cn/db_games/libs/howler.min.js"></script> -->
<!-- <script src="libs/downloadApp.js"></script> --> <!-- <script src="libs/downloadApp.js"></script> -->
<!-- <script src="libs/security.js"></script> --> <!-- <script src="libs/security.js"></script> -->
<!-- <script src="libs/p2.js"></script> --> <!-- <script src="libs/p2.js"></script> -->
......
//https://blog.csdn.net/time1812/article/details/79184641
declare class Howl {
constructor(o: {
src: string[],
autoplay?: boolean,
loop?: boolean,
volume?: number,
onend?: () => void
});
on(eventName: string, fun: () => void, id?: number, once?: number): Howl;
once(eventName: string, fun: () => void, id?: number): Howl;
off(eventName: string, fun: () => void, id?: number): Howl;
_emit(eventName: string, id?: number, msg?: number): Howl;
play(sprite?: number | string, internal?: boolean): number;
fade(from: number, to: number, len: number, id: number): Howl;
rate(rate: number, id: number): Howl | number;
loop(loop?: number, id?: number):Howl | number;
stop(id?:number, internal?:boolean):Howl | number;
// static createVertexBuffer(gl: any, data?: any, drawType?: any): GLBuffer;
// static createIndexBuffer(gl: any, data?: any, drawType?: any): GLBuffer;
// static create(gl: any, type: any, data: any, drawType: any): GLBuffer;
}
\ No newline at end of file
...@@ -4,6 +4,7 @@ import BaseTexture from "../engine/2d/texture/BaseTexture"; ...@@ -4,6 +4,7 @@ import BaseTexture from "../engine/2d/texture/BaseTexture";
import { createTextureSheet } from "../engine/2d/texture/createTextureSheet"; import { createTextureSheet } from "../engine/2d/texture/createTextureSheet";
import { VideoEntity } from "../engine/2d/svga"; import { VideoEntity } from "../engine/2d/svga";
import { TextureCache } from "../engine/2d/utils"; import { TextureCache } from "../engine/2d/utils";
import { Howl, Howler } from 'howler';
// import { Sound, WebAudioDecode, HtmlSound, WebAudioSound } from "../engine/sound"; // import { Sound, WebAudioDecode, HtmlSound, WebAudioSound } from "../engine/sound";
import { Event } from "../engine/2d/events"; import { Event } from "../engine/2d/events";
...@@ -291,7 +292,7 @@ export namespace RES { ...@@ -291,7 +292,7 @@ export namespace RES {
var src = groupName ? resPath + groupName + "/" + str : str; var src = groupName ? resPath + groupName + "/" + str : str;
var p = new Promise((resolve, reject) => { var p = new Promise((resolve, reject) => {
//加载让Howl处理,保证链接正确先 //加载让Howl处理,保证链接正确先
let sound = new Howl({ src: [src] }); let sound = new Howl({ src: [src], preload: true });
soundHash[str] = sound soundHash[str] = sound
comFun && comFun.call(thisObj, soundHash[str], str) comFun && comFun.call(thisObj, soundHash[str], str)
resolve(soundHash[str]) resolve(soundHash[str])
......
import { RES } from "../../module/RES"; import { RES } from "../../module/RES";
import { Howl } from "howler";
let soundOn = true; let soundOn = true;
if (localStorage.getItem('soundOn') == null) { if (localStorage.getItem('soundOn') == null) {
...@@ -54,13 +56,14 @@ export const stopBg = () => { ...@@ -54,13 +56,14 @@ export const stopBg = () => {
bgMusic.stop(); bgMusic.stop();
} }
}; };
//背景音乐有问题,再说
export const playBg = async () => { export const playBg = async () => {
bgMusic = RES.getRes('mapBg.mp3')
if (!bgMusic) { if (!bgMusic) {
bgMusic = await RES.getResAsync('mapBg.mp3'); bgMusic = await RES.getResAsync('mapBg.mp3');
} }
bgMusic.play(); bgMusic.play();
bgMusic.loop() bgMusic.loop(true)
} }
/** /**
...@@ -87,6 +90,5 @@ export const playSound = (type: SoundType) => { ...@@ -87,6 +90,5 @@ export const playSound = (type: SoundType) => {
sound.play(); sound.play();
} else { } else {
RES.getResAsync(type + ".mp3") RES.getResAsync(type + ".mp3")
sound.play();
} }
} }
\ No newline at end of file
...@@ -23,7 +23,9 @@ ...@@ -23,7 +23,9 @@
"webpack": "^4.1.0", "webpack": "^4.1.0",
"webpack-cli": "^3.1.1", "webpack-cli": "^3.1.1",
"webpack-dev-server": "^3.1.0", "webpack-dev-server": "^3.1.0",
"webpack-merge": "^4.1.2" "webpack-merge": "^4.1.2",
"howler": "^2.1.2",
"@types/howler": "^2.1.2"
}, },
"dependencies": { "dependencies": {
"uglifyjs-webpack-plugin": "^2.1.2" "uglifyjs-webpack-plugin": "^2.1.2"
......
...@@ -197,9 +197,16 @@ const mockData = { ...@@ -197,9 +197,16 @@ const mockData = {
"activityId": "111", "activityId": "111",
"nickName": "开发环境", "nickName": "开发环境",
"avatar": "//yun.duiba.com.cn/developer/img/activityTool/slotMachine/virtual.png", "avatar": "//yun.duiba.com.cn/developer/img/activityTool/slotMachine/virtual.png",
// "shareId": "115564",
"type": "kid",//adult
"joinNeedsCredits": 20, "joinNeedsCredits": 20,
"openSound": true,
"gameObj": {
"maxScore": 600,
"bombCount": 1,
"exchangeCount": 2,
"netCount": 3,
"unlockGrade": 128,
"id": "asdqweqwe"
},
} }
}, },
//登录 //登录
...@@ -240,8 +247,8 @@ const mockData = { ...@@ -240,8 +247,8 @@ const mockData = {
"getTools": { "getTools": {
"code": 0, "code": 0,
"data": { "data": {
"bombCount": 3, "bombCount": 2,
"exchangeCount": 0, "exchangeCount": 1,
"netCount": 0 "netCount": 0
}, },
"success": true, "success": true,
......
...@@ -112,6 +112,7 @@ export class Tool { ...@@ -112,6 +112,7 @@ export class Tool {
activityId: string, activityId: string,
nickName: string, nickName: string,
avatar: string, avatar: string,
openSound: boolean,//音效开关
gameObj: {//注意这里面只有id是确定要用的,其他别用 gameObj: {//注意这里面只有id是确定要用的,其他别用
maxScore: number, maxScore: number,
bombCount: number, bombCount: number,
......
import { sendTbNet, TbNetName } from "./TaoBaoNet"; import { sendTbNet, TbNetName } from "./TaoBaoNet";
import { Tool } from "./Tools"; import { Tool } from "./Tools";
import { GDispatcher } from "../engine/2d/events"; import { GDispatcher } from "../engine/2d/events";
import { getSoundOn, toggleSound } from "../module/ctrls/soundCtrl";
export enum TaskType { export enum TaskType {
doFollowShop = "doFollowShop", doFollowShop = "doFollowShop",
...@@ -73,3 +74,22 @@ export function useTools(callback: (s: boolean) => void, type: PropType) { ...@@ -73,3 +74,22 @@ export function useTools(callback: (s: boolean) => void, type: PropType) {
(s) => { callback(s); } (s) => { callback(s); }
) )
} }
/**
* 处理app传过来的音乐状态
*/
export function getSoundStatus() {
var isOn = Tool.globalData.openSound;
//传入的是播放,但是自身关闭了,需要开启
if (isOn && !getSoundOn()) {
toggleSound();
return true;
}
//传入的是关闭的,但是自身开启,需要关闭
if (!isOn && getSoundOn()) {
toggleSound();
return false;
}
//其他情况就是一致的
return isOn
}
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