Jump to content

WebAudio panner + Phaser


Recommended Posts

Hi GreenishFlow,

You have a good example here : https://developer.mozilla.org/fr/docs/Web/API/PannerNode

I 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


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...