GreenishFlow Posted December 17, 2015 Share Posted December 17, 2015 Hi all.I need to use panner in my game based on Phaser. But not sure I understand how to do it. I need to use WebAudio panner.setPosition and listener.setOrientation.May be someone did it already?Thank you Link to comment Share on other sites More sharing options...
Hydromel Posted December 19, 2015 Share Posted December 19, 2015 Hi GreenishFlow,You have a good example here : https://developer.mozilla.org/fr/docs/Web/API/PannerNodeI already used the panner.setPosition but not the listener.setOrientation. Excuse my english, I'm french.function playPas(marcheur) { sourcePas = context.createBufferSource(); //you tell to the source which sound to play //I had a random choice between 3 sounds var choix = Math.round(2*Math.random()); console.log("choix pas "+ choix); switch (choix) { case 0: sourcePas.buffer = pas1Buffer.buf; console.log("play Pas 1"); break; case 1: sourcePas.buffer = pas2Buffer.buf; console.log("play Pas 2"); break; case 2: sourcePas.buffer = pas3Buffer.buf; console.log("play Pas 3"); break; } //You connect the source to the context sourcePas.connect(marcheur.panner); sourcePas.loop=true; //console.log(marcheur.panner); sourcePas.start(0); //console.log("play Pas"); }Then in the update ://ajusting the panner : I had to divide /1000 to have a good sensation of distance var pasx = boy[j].pb.body.x/1000; var pasy = boy[j].pb.body.y/1000; pasx = (pasx - 0.960)*2; //zero is on the center bottom of the screen pasy = (1.088 - pasy)*2; boy[j].panner.setPosition(pasx,pasy,1);I hope it will help ! Link to comment Share on other sites More sharing options...
Recommended Posts