Jump to content

Phaser and Web Audio API


gusstuff
 Share

Recommended Posts

I'm not sure if this is the right place to post this but it does have to do with phaser and would help other trying to do this with phaser in the future. I'm trying to use the web audio api with phaser to create 3d audio in my game. But I'm stuck at setting the orientation of the audio nodes. I'm not sure how to go from the x, y  and rotation values of a sprite to the directional vector and up vector needed to set the orientation.

audioContext.listener.setOrientation(x, y, z, Ux, Uy, Uz);
Link to comment
Share on other sites

I'm pretty sure I worked it out, here is the code:

function updateWithSprite(sprite)    if (sprite.body) {        var rot = sprite.body.rotation + Math.PI / 2;        this.setPosition(sprite.body.x, body.y, 0);        this.setOrientation(Math.cos(rot), Math.sin(rot), 0);        this.setVelocity(sprite.body.velocity.x, sprite.body.velocity.y, sprite.body.velocity.z);    } else {        var rot = sprite.rotation + Math.PI / 2;        this.setPosition(sprite.x, sprite.y, 0);        this.setOrientation(Math.cos(rot), Math.sin(rot), 0);        this.setVelocity(0, 0, 0);    }}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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