慕勒3428872
howler.js对于游戏创作,最好的解决方案之一是使用一个库来解决我们在为Web编写代码时遇到的许多问题,例如howler.js。howler.js将伟大的(但是低级的)Web Audio API抽象为易于使用的框架。如果Web Audio API不可用,它将尝试回退到HTML5音频元素。var sound = new Howl({ urls: ['sound.mp3', 'sound.ogg']}).play();// it also provides calls for spatial/3d audio effects (most browsers)sound.pos3d(0.1,0.3,0.5);wad.js另一个很棒的库是wad.js,它对于产生合成音频特别有用,例如音乐和效果。例如:var saw = new Wad({source : 'sawtooth'})saw.play({ volume : 0.8, wait : 0, // Time in seconds between calling play() and actually triggering the note. loop : false, // This overrides the value for loop on the constructor, if it was set. pitch : 'A4', // A4 is 440 hertz. label : 'A', // A label that identifies this note. env : {hold : 9001}, panning : [1, -1, 10], filter : {frequency : 900}, delay : {delayTime : .8}})游戏的声音另一个类似于Wad.js的库是“ Sound for Games ”,它更关注效果制作,同时通过相对不同(也许更简洁的感觉)API提供类似的功能集:function shootSound() { soundEffect( 1046.5, //frequency 0, //attack 0.3, //decay "sawtooth", //waveform 1, //Volume -0.8, //pan 0, //wait before playing 1200, //pitch bend amount false, //reverse bend 0, //random pitch range 25, //dissonance [0.2, 0.2, 2000], //echo array: [delay, feedback, filter] undefined //reverb array: [duration, decay, reverse?] );}摘要无论您是需要播放单个声音文件,还是创建自己的基于html的音乐编辑器,效果生成器或视频游戏,这些库中的每一个都值得一看。